Hi,
I need help to construct an array totally dynamically including the name.
I have a 'project' array $projects and a 'materials' array $materials.
$projects structure - projid, project
$materials structure - project, workcode, description, cost, tax, invno, vendor.
What I want to do is create an array for each project comprised of elements taken from the materials array. This includes creating the name,
ie: Where $project['project'] = 'house'
create an array called $house and pick all indexes and values from the $materials array having $materials['project'] named 'house'.
QUESTION How can I create the array "$house" from $myVar="$".$project['project']."[]" ($myVar would then be '$house[]')
And then assign values to it:
$myVar=$materials[$i]['description']." - ".$materials[$i]['cost']." - ".$materials[$i]['tax'] ... etc.
I've tried {$myVar}, ($myVar), "$myVar", '$myVar' etc., etc.
Thanks in advance R.
Create dynamic array name - assign values to it
Moderator: General Moderators
Re: Create dynamic array name - assign values to it
$$project['project']
Code: Select all
php > $project = [];
php > $project['project'] = 'house';
php > $$project['project'] = "This is my house.";
php > print_r($house);
This is my house.Re: Create dynamic array name - assign values to it
SOLVED:
Thanks very much celauran. Works fine.
R
Thanks very much celauran. Works fine.
R