Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2014
    Posts
    74
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Finding out child variable name

    Is it possible to find out the name of a child variable?

    I have:

    $_SESSION['cart']['content']['foo']
    $_SESSION['cart']['content']['bar']


    I want to basically do:

    PHP Code:
    foreach ($_SESSION['cart']['content'][*] as $content) {
        echo 
    $content['productname'];

    Notice the star I am using above to express what I am trying to mean.
    Ultimately PHP would echo:

    $_SESSION['cart']['content']['foo']['productname']
    $_SESSION['cart']['content']['bar']['productname']

  • #2
    New Coder
    Join Date
    Jan 2014
    Posts
    74
    Thanks
    11
    Thanked 0 Times in 0 Posts
    my shopping cart is a total POS and I need to start from scratch and sleep. Thanks anyway.

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    PHP Code:

     <?php
    $_SESSION
    ['cart']['content']['number'][1]['sizes'] = '1'
    $_SESSION['cart']['content']['number'][2]['sizes'] = '1'


    foreach (
    $_SESSION['cart']['content'] as $key => $value) {
        foreach (
    $value as $subkey => $subvalue) {
            foreach (
    $subvalue as $subsubkey => $subsubvalue) {
                echo 
    'key:'.$key.' value:'.$value.' subkey:'.$subkey.' subvalue:'.$subvalue.' subsubkey:'.$subsubkey.' subsubvalue:'.$subsubvalue.'<p>';
            }
        }
        
    }  
    ?>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •