Hi I have a problem regarding multi-dimension array. I have a set of array looking like this
JavaScript
x
array:3 [▼
0 => array:1 [▼
"tree" => "0"
]
1 => array:1 [▼
"tree" => "2"
]
2 => array:1 [▼
"tree" => "0"
]
]
the array is from
JavaScript
dd($this->treeArray);
how do I want to get the array which the value is 0. Expected result/filter For example:
JavaScript
array:2 [▼
0 => array:1 [▼
"tree" => "0"
]
1 => array:1 [▼
"tree" => "0"
]
]
or
array:1 [▼
0 => array:1 [▼
"tree" => "2"
]
]
if changing the index is impossible, its ok.. Thank you
Advertisement
Answer
As you are using Laravel, you could use array helper such as this
You can use like this:
JavaScript
use IlluminateSupportArr;
$newTreeArray = Arr::where($this->treeArray, function ($tree) => $tree['tree'] === "0");