Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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:


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
Advertisement