I have a php related question?

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
In a php data strucutre,
PHP:
global $database;
$database = array(
 array('something', 'something_else'),
 array('anotherthing', 'yet_another'),
 array('almost_there', 'last_thing'),
);
you would extract as follows,
PHP:
print $database[0][0];  // should print the first scalar from the first array
so if i went,
PHP:
global $i;
$i=0;
foreach ($database as $a)
{
 if (!$a[$i]) {break;} else {print $a[$i].'<br>';
}
// in this $a becomes the array's inside the data structure ?
&
PHP:
global $i;
$i=0;
foreach ($database as $a)
{
 if (!$database[$i][0]) {break;} else { print $database[$i][0].'<br>';}
 $i++;
}
// this is now refrencing to the data structure that contains the arrays?
So this should print the whole data structure?
PHP:
foreach ($database as $a)
{
 foreach ($a as $b)
 {
  if (!$b) {break;} else { print $b.'<br>';}
  $i++;
 }
}

What I am aiming to do is this.

Pass a varing amount of arrays to a include. The amount of scalars in the arrays is set and wont be more or less(some might be empty).
I can get them across with "global" easily enough. What is getting me is that foreach scalar in an array, I need to assign another value to another data structure.

would this work?
PHP:
global $ii;
$ii=0;
foreach ($database as $a)
{
 foreach ($a as $b)
 {
  if (!$b) {break;} else { print $b.'<br>';}
  array_push($data2[$i][$ii],$b);
  $ii++;
 }
 $i++;
}
// cant figure this one out, example doesn't work ?

Basically for every scalar in each array in the 1st data structure, there needs to be one set in the 2nd data structure.

? ? ?

If anyone could try and explain how to do this I would greatly appreciate it.
I am sure I can return a favor.

Regards,
Edit:
Does it matter how I define the "$data2"?
 
Last edited:
Top