0

I know its easy but unfortunately I'm stuck in it. I've a array like this:-

Array
(
[0] => Array
    (
        [id] => 91
        [title] => final test sql question
        [description] => 
final test sql questions


        [status] => 1
        [testId] => 29
        [questionOrderNo] => 1
        [createdAt] => 2015-09-05 11:02:06
        [updatedAt] => 0000-00-00 00:00:00
    )

)

How can i read its value like id and title...

Umair Malik
  • 1,403
  • 3
  • 30
  • 59

3 Answers3

1

That is a multidimensional array you can access it through its index. i.e array[numeric index][text reference]

$myarr = array(
    0 => array(
     'id' => '91',
     'title' => 'final test sql question',
     'description' => 'final test sql questions',
     'status' => '1',
     'testId' => '29',
     'questionOrderNo' => '1',
     'createdAt' => '2015-09-05 11:02:06',
     'updatedAt' => '0000-00-00 00:00:00'
     )
);
echo $myarr[0]['status'];
Alex Andrei
  • 7,315
  • 3
  • 28
  • 42
kurt
  • 1,146
  • 1
  • 8
  • 18
1

You can access it by:

echo $yourArray[0]['id'];
echo $yourArray[0]['title'];

If you want to access all values use 'foreach'

foreach($yourArray as $key => $val)
{
 echo $val['id'];
 echo $val['title'];
}
aldrin27
  • 3,407
  • 3
  • 29
  • 43
0

$id = $arr[0]['id']; and if they are many of those all you have to do is foreach($bigarr as $arr){ echo $arr['id']; }

Peter Chaula
  • 3,456
  • 2
  • 28
  • 32