我想创建这样的数据结构:
pos, desc, price
0 , myKey, myValue
1 , myKey2, myvalue
因此,我可以使用foreach查看数组,并获得键和值。
应该很容易,但我很吃力,这就是我尝试过的:
$variationsList = array();
for($x=1;$x<6;$x++)
{
if (get_post_meta($post_id, "variationDesc" . $x, true) != '')
{
$variationsList["desc"] = get_post_meta($post_id, "variationDesc" . $x, true);
$variationList["price"] = get_post_meta($post_id, "variationPrice" . $x, true);
}
}
将包含以下两个键的新数组附加到您的数组:
$variationsList[] = array('desc' => ..., 'price' => ...);