1

I'm new to laravel my previous project i used Datatable Jquery Server side processing.

My table was

Id    Name   Age    Status
1     Aaa    18      1
2     Abb    18      1
3     Acc    18      2

If am fetching result from database it in Laravel it retrieves following

array(
0=>object(stdClass){
 ["id"]=> 1,
 ["Name"]=>  "Aaa",
 ["Age"]=> 18,
 ["Status"]=>1 
 },
 1=>object(stdClass){
 ["id"]=> 1,
 ["Name"]=>  "Abb",
 ["Age"]=> 18,
 ["Status"]=>1 
 } ,
 2=>object(stdClass){
 ["id"]=> 3,
 ["Name"]=>  "Acc",
 ["Age"]=> 18,
 ["Status"]=>1 
 } )

etc..,

But I need

array(
  0=>{  
     1,
     Aaa,
     18,
     1},
  1=>{  
     2,
     Abb,
     18,
     1},
,
  2=>{  
     3,
     Acc,
     18,
     1});

1 Answer 1

2

The result of a query will be a collection. So, you can use the map() collection method with array_values():

$collection->map(function($i) {
    return array_values($i->toArray());
})->toArray();

And if it's an array for some reason, use array_map():

array_map(function($i) {
    return array_values((array)$i);
}, $array);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.