Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
Array ( [0] => Array ( [Name] => [0] => [ConditionValue] => 1 [1] => 1 ) 
    [1] => Array ( [Name] => [0] => [ConditionValue] => 2 [1] => 2 ) 
    [2] => Array ( [Name] => [0] => [ConditionValue] => 4 [1] => 4 ) 
    [3] => Array ( [Name] => [0] => [ConditionValue] => 8 [1] => 8 ) 
    [4] => Array ( [Name] => [0] => [ConditionValue] => 16 [1] => 16 ) 
    [5] => Array ( [Name] => [0] => [ConditionValue] => 32 [1] => 32 ) 
    [6] => Array ( [Name] => [0] => [ConditionValue] => 64 [1] => 64 ) 
    [7] => Array ( [Name] => [0] => [ConditionValue] => 128 [1] => 128 ) 
    [8] => Array ( [Name] => Exterior Hoist [0] => Exterior Hoist [ConditionValue] => 256 [1] => 256 ) 
    [9] => Array ( [Name] => [0] => [ConditionValue] => 512 [1] => 512 ) 
    [10] => Array ( [Name] => [0] => [ConditionValue] => 1024 [1] => 1024 ) 
    [11] => Array ( [Name] => [0] => [ConditionValue] => 2048 [1] => 2048 ) 
    [12] => Array ( [Name] => [0] => [ConditionValue] => 4096 [1] => 4096 ) 
    [13] => Array ( [Name] => [0] => [ConditionValue] => 8192 [1] => 8192 ) 
    [14] => Array ( [Name] => [0] => [ConditionValue] => 16384 [1] => 16384 ) 
    [15] => Array ( [Name] => [0] => [ConditionValue] => 32768 [1] => 32768 ) 
    [16] => Array ( [Name] => Parcel [0] => Parcel [ConditionValue] => 65536 [1] => 65536 ) 
    [17] => Array ( [Name] => Cheques [0] => Cheques [ConditionValue] => 131072 [1] => 131072 )
    [18] => Array ( [Name] => OuterArea [0] => OuterArea [ConditionValue] => 262144 [1] => 262144 ) 
    [19] => Array ( [Name] => [0] => [ConditionValue] => 524288 [1] => 524288 ) 
    [20] => Array ( [Name] => [0] => [ConditionValue] => 1048576 [1] => 1048576 ) 
    [21] => Array ( [Name] => V [0] => V [ConditionValue] => 2097152 [1] => 2097152 )
    [22] => Array ( [Name] => Wheelchair [0] => Wheelchair [ConditionValue] => 4194304 [1] => 4194304 ) 
    [23] => Array ( [Name] => M50 [0] => M50 [ConditionValue] => 8388608 [1] => 8388608 ) 
    [24] => Array ( [Name] => Executive Car (Silver) [0] => Executive Car (Silver) [ConditionValue] => 16777216 [1] => 16777216 ) 
    [25] => Array ( [Name] => Two M50s [0] => Two M50s [ConditionValue] => 33554432 [1] => 33554432 ) 
    [26] => Array ( [Name] => Special [0] => Special [ConditionValue] => 67108864 [1] => 67108864 ) 
    [27] => Array ( [Name] => Animal [0] => Animal [ConditionValue] => 134217728 [1] => 134217728 ) 
    [28] => Array ( [Name] => COD Parcel [0] => COD Parcel [ConditionValue] => 268435456 [1] => 268435456 ) 
    [29] => Array ( [Name] => 9 seater [0] => 9 seater [ConditionValue] => 536870912 [1] => 536870912 ) 
    [30] => Array ( [Name] => 6 seater [0] => 6 seater [ConditionValue] => 1073741824 [1] => 1073741824 ) 
    [31] => Array ( [Name] => 7 seater [0] => 7 seater [ConditionValue] => 2147483648 [1] => 2147483648 ) 
    [32] => Array ( [Name] => Wagon [0] => Wagon [ConditionValue] => 4294967296 [1] => 4294967296 ) 
    [33] => Array ( [Name] => Maxi10str [0] => Maxi10str [ConditionValue] => 8589934592 [1] => 8589934592 ) 
    [34] => Array ( [Name] => Bike [0] => Bike [ConditionValue] => 17179869184 [1] => 17179869184 ) 
    [35] => Array ( [Name] => NonMaxi [0] => NonMaxi [ConditionValue] => 34359738368 [1] => 34359738368 ) 
    [36] => Array ( [Name] => NonMaxiOrMulti [0] => NonMaxiOrMulti [ConditionValue] => 68719476736 [1] => 68719476736 ) 
    [37] => Array ( [Name] => [0] => [ConditionValue] => 137438953472 [1] => 137438953472 ) 
    [38] => Array ( [Name] => Towbar [0] => Towbar [ConditionValue] => 274877906944 [1] => 274877906944 ) 
    [39] => Array ( [Name] => NO DISPATCH [0] => NO DISPATCH [ConditionValue] => 549755813888 [1] => 549755813888 ) )

I have a reasonably simple multi dimensional array, that i want to display the "name" of a certain array index...

for example say i have the value 22, i want to be able to display "wheelchair".

i get a little lost when it comes to the second dimension.

thus far i have tried..

$result is the multidimensional array above.

$resulting_bits is this array (it is built dynamically and could have up to 40 values):

Array ( [0] => 23 [1] => 26 [2] => 33 )

this is the code i have at the moment

foreach($resulting_bits as $val) {

echo $val;

echo "<br>";

$answer = ($result[$val]);

foreach($answer as $conditionname) {


print_r ($conditionname);
echo "<br>";
echo $conditionname[Name];
}

this gives me

Array ( [0] => 23 [1] => 26 [2] => 33 )
23
M50
MM50
M8388608
88388608
826
Special
SSpecial
S67108864
667108864
633
Maxi10str
MMaxi10str
M8589934592
88589934592
8

which seems odd to me... how do i just display the "name"??

share|improve this question
1  
echo $result[22]["Name"] ? Or do you need an iteration? –  dognose Sep 20 '13 at 0:15
    
"$resulting_bits is this array (it is built dynamically and could have up to 40 values):" What do you mean by "this array"? Are you saying that you want to retreive all of the name's that correspond to the indexes stored in $resulting_bits?\ –  KHMKShore Sep 20 '13 at 0:34
add comment

1 Answer

up vote 2 down vote accepted

the second for loop is unnecessary! It is not an associative array at that point.

foreach($resulting_bits as $val) {

echo $val;

echo "<br>";

$answer = ($result[$val]);
$name = $answer['Name'];
echo $name;

}

I would personnaly just do:

foreach($resulting_bits as $val) {

   echo $result[$val]['Name'];

}
share|improve this answer
    
You're absolutely right. –  KHMKShore Sep 20 '13 at 0:41
    
what is $result? –  Emilio Gort Sep 20 '13 at 0:41
    
the question states "$result is the multidimensional array above" –  Neo Sep 20 '13 at 0:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.