#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    40
    Rep Power
    0

    How do i access all the elements in php using loop


    PHP Code:
    {

        
    "0":{
            
    "season_id":"87",
            
    "season_name":"New show season 1",
            
    "season_description":"First Season 1",
            
    "noOfVid":193,
            
    "seasonsImg":"../images/season-image/1.jpg"
        
    },
        
    "1":{
            
    "season_id":"89",
            
    "season_name":"New show season 2",
            
    "season_description":"Show 2 description.",
            
    "noOfVid":200,
            
    "seasonsImg":"../images/season-image/3.jpg"
        
    },
        
    "2":{
            
    "season_id":"100",
            
    "season_name":"Season 3",
            
    "season_description":"season ",
            
    "noOfVid":33,
            
    "seasonsImg":"../images/season-image/4.jpg"
        
    },
        
    "ar":{
            
    "season_id":"1000",
            
    "season_name":"Season000 3",
            
    "season_description":"season21 ",
            
    "noOfVid":33,
            
    "seasonsImg":"../images/season-image/4.jpg"
        
    }


    How do i access "ar" separately?
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,071
    Rep Power
    9398
    That's JSON, so decode it first and then use ["ar"] (if you decoded it as an array) or ->ar (if you decoded it as an object).

    Comments on this post

    • sunny1234567890 agrees
  4. #3

  5. Join Date
    Jul 2013
    Location
    Melbourne
    Posts
    43
    Rep Power
    0
    Code:
    <?php $arr = array("one", "two", "three"); reset($arr); while (list(, $value) = each($arr)) {     echo "Value: $value<br />\n"; }  foreach ($arr as $value) {     echo "Value: $value<br />\n"; } ?>
    I think this is the procedure. If not please recorrect it.

    Comments on this post

    • sunny1234567890 agrees
    • Jacques1 disagrees : Wut?
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by PeterSullivan
    I think this is the procedure.
    Um, what?

    Congratulations, you've discovered the foreach loop. But what does this have to do with the question?
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo