【发布时间】:2021-08-26 04:10:57
【问题描述】:
我有一个这样的数组:
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)
}
}
}
我想在“先决条件”中做一个 foreach:
$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;
}
}
}
}
我需要在第二个 foreach 中使用 $value2['champ'],其中 $value2['champ'] 是“tranche.fus.fup_id。所以我需要分解它以获得 ['tranche']['fus']['fup_id']。
如何使用爆炸?
谢谢大家:)
【问题讨论】:
-
当前你有:$value2['champ'] = "tranche.fus.fup.fup_id" 你需要:$value2['champ']['tranche']['fus'] ['fup']['fup_id'] = "" 对吗?
-
我需要将 ['champ'] 替换为 ['tranche']['fus']['fup']['fup_id']。如果 champ 包含 '.',则获取 $value2['tranche']['fus']['fup']['fup_id'] 的值
标签: php arrays laravel explode