2

please help me to solve this problem that how to die and dump 2D array in laravel and count array in an array.. i tried this but not working

$arr=collect($request->input('title['+$i+']'));
    dd($arr->count());

also tried this code

$arr=collect($request->input('title[0]'));
    dd($arr->count());
Jamal Ahmad
  • 571
  • 2
  • 9
  • 25

5 Answers5

1

dd($request->all()) will display contents of the array.

If you want to see the title, do this:

dd($request->title);
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
1

try to use:

echo count($arr); dd($arr);

or

echo count($arr); print_r($arr); die;

Isaac_ods
  • 11
  • 1
1

You do not say that you need to count them in your questions but here you go:

The aray:

  $arrayname= array(
            array('a', 'b', 'c'),
            array('r', 't','y', 'u'),
        );

The function

    for ($i=0;  $i < count($arrayname); $i++){
        $singlearray[$i]= count($arrayname[$i]);
    }

Result

array:2 [▼
  0 => 3
  1 => 4
]
Onix
  • 2,129
  • 2
  • 17
  • 26
0
$a = $request->all();
$flatArray = [];
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($a));
foreach($it as $v) {
  $array[] = $v;
}
dd(count($flatArray));    

Resource: How to Flatten a Multidimensional Array?

Community
  • 1
  • 1
0

i get it from the other site... Answer here

dd(count(request('title')[0])); dd(count(request('title')['age']));

Jamal Ahmad
  • 571
  • 2
  • 9
  • 25