假设我需要三个阵列,福特、雪佛兰和道奇。每个数组包含三个项目:
$ford['engine'] = 'something';
$ford['color'] = 'something';
$ford['price'] = 'something';
$chevy['engine'] = 'something';
$chevy['color'] = 'something';
$chevy['price'] = 'something';
$dodge['engine'] = 'something';
$dodge['color'] = 'something';
$dodge['price'] = 'something';
我可以把它写出来没问题,而且不需要太长时间。但是,假设我需要制作五十或六十个阵列,所有阵列都有十到二十个不同的项目。我想在每个数组文件的顶部放置一个变量来表示数组名称,但我对语法不太清楚,我不太熟悉 $$ 或者我如何将它与数组一起使用:
$name = 'ford';
$(I want this to be "$name")['engine'] = 'something';
$(I want this to be "$name")['color'] = 'something';
$(I want this to be "$name")['price'] = 'something';
我也考虑过这样做:
$name = 'ford';
$view[$name.'_engine']
$view[$name.'_color']
$view[$name.'_price']
我可以就解决此问题的最佳方法获得一些建议吗?