<?php
$facet_fields = array (
"dx-tx295" => array (
"T",1348,),
"dx-z1" => array (
"F",1,
"G",2,
"E",3,
"D",4,
"C",5,
"H",6,
"B",7,
"I",8,
"J",9,
"K",10,
"A",11,
"L",12,
"M",13,)
)
$catalogue = array();
$value = array();
for ($x=1;$x<count($facet_fields);$x++)
{
for($y=0;$y<count($facet_fields[$x]);$y+2)
{
$current = $facet_fields[$x];
$spot = ($current[$y] => $current[$y+1]);
array_push($value, $spot);
}
}
for($i=0;$i<count($facet_fields);$i++)
{
$spot2 = ($facet_fields[$i]=>$value);
array_push($catalogue, $spot2);
}
print $catalogue
print $value
?>
I am trying to assign each number in the first array to its associated letter, and then add the association to a spot in a new array value. Then I am trying to associate the value arrays to the facet_field arrays and add them to catalogue. It is having a problem with the assigned associations such as the line with $spot.
Is it possible to do this? Or can I not include this many variables in an association? How would I make an associated array in an array like this?
Thanks.
Is it possible to do this?
Yes, it is possible to transform the array.
Or can I not include this many variables in an association?
No, that is not a problem. The $facet_files array is small and processable. Memory problems arise only, when arrays are really, really large.
How would I make an associated array in an array like this?
By iterating over the $facet_fields
array, getting its keys and values and inserting them into a new array with the desired structure. I think you make this a bit complicated, by using for-loops and indexing the $values array with the iterator variable. When you insert new values into an array they are automatically indexed numerically. In other words: stop doing $facet_fields[$x]
.
You might provide the $catalog = array( key => value );
because it's not really clear which structure the target array must have.