开发者

Create associative multi-dimensional array

开发者 https://www.devze.com 2023-01-03 13:23 出处:网络
I have 3 variables, each one holding a different information and send values from a text file dynamicaly. I want to put them in a Associative multi-dimensional array.

I have 3 variables, each one holding a different information and send values from a text file dynamicaly. I want to put them in a Associative multi-dimensional array.

let's say :

$product sends car, truck, train, etc.
$price sends 1000, 3000,  1500, etc.
$year  sends 1997, 1980, 2008, etc.

How to create a function which generates an array as follow, when i execute print_r(myarray):

Array (
[0开发者_运维百科] => Array ( [product] => car [price] => 1000 [year] => 1997 ) 
[1] => Array ( [product] => truck [price] => 3000 [year] => 1980 )
[2] => Array ( [product] => train [price] => 1500 [year] => 2008 )) and so on. 


Take a look at this question: Define 2D array with loops in php

0

精彩评论

暂无评论...
验证码 换一张
取 消