Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php string to array question ??

  • 20-12-2010 02:10PM
    #1
    Registered Users, Registered Users 2 Posts: 648
    ✭✭✭


    hi guys.

    can anyone tell me how i would convert the below string into an array (so i can run foreach on it)
    tnx

     Array
    (
      [0] => stdClass Object
            (
                [isJuliaFlagged] => 1
                [forum] => test
                [parent] => 
                [isApproved] => 1
                [author] => stdClass Object
                    (
                        [name] => name in here
                        [url] => 
                        [profileUrl] => 
                        [emailHash] => 4f27ad3e4e2e0c3b91ca10d689315afd
                        [avatar] => stdClass Object
                            (
                                [permalink] => 
                                [cache] =>
                            )
    
                        [isAnonymous] => 1
                        [email] => email@gmail.com
                    )
    
                [isDeleted] => 
                [isFlagged] => 
                [dislikes] => 0
                [createdAt] => 2010-12-03T12:01:53
                [isSpam] => 
                [thread] => 183560705
                [points] => 0
                [likes] => 0
                [message] => test 3
                [ipAddress] => 
                [id] => 106296502
                [isHighlighted] => 
            )
    
        [1] => stdClass Object
            (
                [isJuliaFlagged] => 1
                [forum] => test
                [parent] => 
                [isApproved] => 1
                [author] => stdClass Object
                    (
                        [name] => name in here
                        [url] => 
                        [profileUrl] => 
                        [emailHash] => 4f27ad3e4e2e0c3b91ca10d689315afd
                        [avatar] => stdClass Object
                            (
                                [permalink] => 
                                [cache] =>
                            )
    
                        [isAnonymous] => 1
                        [email] => email@gmail.com
                    )
    
                [isDeleted] => 
                [isFlagged] => 
                [dislikes] => 0
                [createdAt] => 2010-12-03T12:01:53
                [isSpam] => 
                [thread] => 183560705
                [points] => 0
                [likes] => 0
                [message] => test 3
                [ipAddress] => 
                [id] => 106296502
                [isHighlighted] => 
            )
    )
    
    
    Tagged:


Welcome!

It looks like you're new here. Sign in or register to get started.

Comments

  • Closed Accounts Posts: 18,163 Liam Byrne
    ✭✭✭✭


    Which string ?


  • Registered Users, Registered Users 2 Posts: 648 ChicoMendez
    ✭✭✭


    the code in the code field - i know you say its an array - but suppose itspresented to me in a string variable....


  • Registered Users, Registered Users 2 Posts: 981 fasty
    ✭✭✭


    The explode function will return an array given a delimited string.

    But as mentioned, what you posted ain't no string!


  • Registered Users, Registered Users 2 Posts: 171 conorcan2
    ✭✭


    Where did you get that 'string' from? I.e. What line of PHP code produced that 'string'? I'm going to call it '$yourVariable'. See, it looks like an array already. An array that contains objects as it's values. Try this (the only thing you need to change is $yourVariable.

    [PHP]

    foreach($yourVariable as $arrayKey=>$objectReference){

    echo $objectReference->isJuliaFlagged; // prints '1' and then '1'

    }

    [/PHP]


  • Registered Users, Registered Users 2 Posts: 241 fcrossen
    ✭✭


    Since PHP5 foreach will iterate over objects as well as arrays.

    A recursive function will do this nicely for you.


  • Advertisement

Welcome!

It looks like you're new here. Sign in or register to get started.
Advertisement