aj_blk
aj_blk

Reputation: 314

get value from two dimensional array

Code

$two[0][0]=100;
$two[1][0]=110;
$two[2][0]=120;

var_dump($two);

echo "<br> two[0][0]=$two[0][0]";
echo "<br> two[1][0]=$two[1].0";
echo "<br> two[2][0]=$two[2]";

Output

array (size=3)
  0 => 
    array (size=1)
      0 => int 100
  1 => 
    array (size=1)
      0 => int 110
  2 => 
    array (size=1)
      0 => int 120

( ! ) Notice: Array to string conversion 

two[0][0]=Array[0]
two[1][0]=Array.0
two[2][0]=Array

How to get the value from this two-dimensional array ? I was able to use get output for single dimension array using echo $single[1]

Upvotes: 1

Views: 134

Answers (2)

A l w a y s S u n n y
A l w a y s S u n n y

Reputation: 38512

Try to change this way,

$two[0][0]=100;
$two[1][0]=110;
$two[2][0]=120;

echo "<pre>";
print_r($two);
echo "</pre>";

echo "\n";
//concatenate your 2d array with string here
echo "two[0][0]=".$two[0][0]."\n"; 
echo "two[1][0]=".$two[1][0]."\n";
echo "two[2][0]=".$two[2][0]."\n";

Upvotes: 0

Tamil Selvan C
Tamil Selvan C

Reputation: 20209

When use echo "<br> two[0][0]=$two[0][0]";

it read as $two[0]. "[0]" which return output as Array[0]

Try

echo "<br> two[0][0]=" . $two[0][0]; 

or

echo "<br> two[0][0]={$two[0][0]}";

Change your code as

$two[0][0]=100;
$two[1][0]=110;
$two[2][0]=120;

var_dump($two);

echo "<br> two[0][0]={$two[0][0]}";
echo "<br> two[1][0]={$two[1][0]}";
echo "<br> two[2][0]={$two[2][0]}";

Upvotes: 1

Related Questions