多次元配列とプッシュ方法に関して、PHP のコーディングを理解するのに苦労しています。アイデアは、「属性」と「属性値」をプッシュすることです
私は以下の式を試しました
$i = 0;
$array = array();
foreach($node as $a)
{
$strAtt = $node->PROP[$i]->attributes();
$strVal = $node->PROP[$i]->PVAL;
$output = $output.$strAtt." : ".$strVal."<BR>";
$array[] = ($strAtt => $strVal);
$array[] = ( $strAtt => $strVal); 私に多くの成功を与えません。私はarray_push($array, $strAtt => $strVal) を試しました - 運が悪い..
追加の質問として、配列をループして多次元値を出力するにはどうすればよいですか?
新しいコード
while ($z->name === 'RECORD')
{
$node = new SimpleXMLElement($z->readOuterXML());
$Print = FALSE;
$output = "";
$i = 0;
foreach($node as $a)
{
$strAtt = $node->PROP[$i]->attributes();
$strVal = $node->PROP[$i]->PVAL;
$output = $output.$strAtt." : ".$strVal."<BR>";
$array[$strAtt] = $strVal;
if(($i == 6) && ($node->PROP[$i]->PVAL == $ProductLookup))
{
$Print = TRUE;
$Product = $node->PROP[$i]->PVAL;
}
$i++;
}
if($Print == TRUE) {
echo $output;
echo "Product : ".$Product."<br>";
var_dump($array);
}
//print_r($array);
$print = FALSE;
// go to next <product />
$z->next('RECORD');
}
新しいコードが追加されました。なんらかの理由で、$Output がテキストでいっぱいなのに、$array をダンプすると完全に空になりますか?