Home > Mobile >  Get value from Index and Implode that value In Laravel/Php
Get value from Index and Implode that value In Laravel/Php

Time:03-04

My Controller Code

$StudentData =  StudentModel::getStudentList();
        //dd($StudentData);
        foreach ($StudentData as $data)
        {
             print_r(array($data->Student_name));
             
        }

when i Use dd() commend and I get index values like

Illuminate\Database\Eloquent\Collection {#588 ▼
  #items: array:2 [▼
    0 => App\Models\Student {#585 ▼
      #attributes: array:4 [▶]
      #original: array:4 [▼
          "StudentId" => 2
        "Student_register_number" => 11
        "Student_name" => "Tom"
        "Student_make_percentage" => "69.00"
      ]
      #guarded: array:1 [▶]
    }
    1 => App\Models\Student {#575 ▼
      #attributes: array:4 [▶]
      #original: array:4 [▼
        "StudentId" => 2
        "Student_register_number" => 11
        "Student_name" => "John"
        "Student_make_percentage" => "65.00"
      ]

when i Use print_r(array($data->Student_name)); and run the out put i get Like This

Array
(
    [0] => Tom
)
Array
(
    [0] =>John
)

what actually result i want is

array (2)=>
[
   '0'=>Tom,
   '1'=>'john',
]

how i want to get All Student_name alone from index .and store that as index value as above

CodePudding user response:

Try this...

 return StudentModel::getStudentList()->pluck('Student_name')->toArray();
  • Related