Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hecate0211's avatar

get array value from controller

i have an array like this, this array from my controller and i parse to my view before i send to my view i try to see my array with dd(myArray); and my array like this

  433 => array:5 [▼
    "no" => 17000767
    "name" => "Verizon"
    "price" => "1,485,000,000.00"
    0 => "Motorola"
  ]

oh btw this is 2 array, i use merge between my 2 array.. how to get 0=> "Motorola" in my view??

0 likes
3 replies
cre3z's avatar

can you show us how you are displaying it in your view? Why not just name the 0 key to 'model_name' or 'phone' and you can access it in your view array['model_name'] etc.

RamjithAp's avatar

Try this in your view


{{ $data[0] }} or  {{ $data->0 }} or <?php echo $data[0]; ?>

cre3z's avatar

@RamjithAp your way will work but looking at his dataset I think it might better to name the key something. You never know how the data is constructed and if 'Motorola' will always be at position zero so to make sure the data displayed is always correct it would be better to name it or ensure that your array is constructed in such an order where 'Motorola' will always be 0.

Please or to participate in this conversation.