我有与每个不同键相关联的大量数据。我计划在php
中以这种格式存储数据$item = array(
(
"key" : key-value;
"features" : array-of-features;
"small_images" : array-of-small_images;
),
(
"key" : key-value;
"features" : array-of-features;
"small_images" : array-of-small_images;
),
(
"key" : key-value;
"features" : array-of-features;
"small_images" : array-of-small_images;
)
);
是否知道我如何创建像上面提到的数据结构以及如何在PHP中访问其值。如果有其他的方法,请告诉我。
EDIT:注意这里的数据是array的array-of-features和array-of-small_images是一个关联数组,其中包含与主主相同的键和与其值相同的值
如果键唯一,则关联数组是理想的解决方案:
$items['key1']['features'] = array-of-features;
$items['key1']['small_images'] = array-of-small_images;
$items['key2']['features'] = array-of-features;
$items['key2']['small_images'] = array-of-small_images;
...
然后,可以用foreach:
循环项foreach($items as $key => $item) {
echo "n<pre>$key => " . print_r($item, 1) . "</pre>";
}