April 17, 2012

how to reach into PHP nested arrays?

Question by user837208

I’ve a nested array whose print_r looks like this-

Array
(
    [keyId] => Array
        (
            [hostname] => 192.168.1.127
            [results] => Array
                (
                    [1] => false
                    [2] => false
                    [3] => false
                )

            [sessionIDs] => Array
                (
                    [0] => ed9f79e4-2640-4089-ba0e-79bec15cb25b
                )

        )

I would like to process(print key and value) of the “results” array. How do I do this?

I am trying to use array_keys function to first get all the keys and if key name is “results”, process the array. But problem is array_keys is not reaching into the “results”

Answer by Jon

foreach($array['keyId']['results'] as $k => $v) {
    // use $k and $v
}

Answer by Starx

One way to navigate through the array is this.

//Assuming, your main array is $array
foreach($array as $value) { //iterate over each item

   if(isset($value['results']) && count($value['results'])) { 
   // ^ check if results is present

       //Now that we know results exists, lets use foreach loop again to get the values
       foreach($value['result'] as $k => $v) {
           //The boolean values are now accessible with $v
       }
   }
}
October 29, 2010

div in front of another resets jQuery hover animation. how to prevent this?

Question by MauF

i have an animate effect applied to 4 divs in order to create a blinds effect: when you hover over the first box it grows , the other 3 shrink and when you “mouseout” all 4 return to 25% of the total height.

i want to insert a nested div inside each box (in front, actually with absolute positioning) in order to present some text and links, but every time the mouse hovers over this new div, the animation resets (the mouseout event runs).

how can i make the nested div invisible to the animation? or include it such way that it is invisible to the animation code but the urls work properly?

the example is here:

jquery problem

all code is inline for this demo.

thanx in advance.

Answer by Starx

Solved, check here

The trick to add the selector $("#one > *")

...

Please fill the form - I will response as fast as I can!