Jump to content

multi-dimensional arrays in php making my brain hurt


Recommended Posts

Posted (edited)

i dont do php often and when i do it's by cobbling together samples from all over using a generic knowledge of scripting and reading the manual. this is beyond cobbling. a 3 dimensional (i think) array with 2 normal ones and an associative one.

all i want is the name fields outputted to a webpage. simple really but I'm a bit lost here. extreme brain strain :(

 

the print_r gives this

 

Array
(
   [words] => Array
       (
           [2009-07-03] => Array
               (
                   [0] => Array
                       (
                           [query] => "Sarah"
                           [name] => Sarah
                       )

                   [1] => Array
                       (
                           [query] => "michael"
                           [name] => michael
                       )

                   [2] => Array
                       (
                           [query] => Alaska
                           [name] => Alaska
                       )

               )

       )

   [as_of] => 1246663258
)

 

help!!

 

thx

Edited by browolf
Posted

foreach( $origarray['words']['2009-07-03'] as $thing )
{
   echo "
name: {$thing['name']}\n";
}

Or perhaps:

foreach( $origarray['words'] as $days )
{
   foreach( $days as $day )
   {
       foreach( $day as $thing )
       {
           echo "
name: {$thing['name']}\n";
       }
   }
}

Posted

thx anyways. I spent about 3 hours earlier figuring it out lol.

what i've done is

 

$keydate =  key($decode["words"]);
$count = count($decode["words"][$keydate]); //counting the number of status

$strdmp="";

for($i=0;$i<$count;$i++){
 //echo $decode["words"][$keydate][$i][name]."
";
 $strdmp = $strdmp . $decode["words"][$keydate][$i][name]."
";
} 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...