I have an array like that:
array(5) { ["code"]=> int(1) ["messageError"]=> string(27) "La typologie est incorrecte" ["model"]=> string(3) "lot" ["grp_regles"]=> array(1) { [0]=> array(1) { [0]=> array(3) { ["champ"]=> string(21) "lot_surface_habitable" ["comparaison"]=> string(7) "between" ["valeurAttendue"]=> array(2) { [0]=> int(16) [1]=> int(40) } } } } ["prerequis"]=> array(2) { [0]=> array(3) { ["champ"]=> string(6) "typ_id" ["comparaison"]=> string(1) "=" ["valeurAttendue"]=> int(1) } [1]=> array(3) { ["champ"]=> string(22) "tranche.fus.fup.fup_id" ["comparaison"]=> string(1) "=" ["valeurAttendue"]=> int(1) } } }
I want to do a foreach in “prerequis”:
$modelRetrieve = $this->retrieveModel($model); $modelFind = $modelRetrieve::find($id); $arrayError=[]; $query = ''; $path = storage_path() . "/json/controle.json"; $json = file_get_contents($path); foreach (json_decode($json,true) as $key => $value) { $test = true; var_dump($value); if($value['model'] === $model ){ foreach ($value['prerequis'] as $key => $value2) { if( $test && $modelFind[$value2['champ']] == (int)$value2["valeurAttendue"] ) { $test = true; } } } }
I need in second foreach to use in $value2['champ']
where $value2['champ']
is “tranche.fus.fup_id. So I need to explode that to have ['tranche']['fus']['fup_id']
.
How to use explode with that ?
thanks everyone 🙂
Advertisement
Answer
you can use laravel data_get
helper:
data_get($value2, $value2['champ'])