[FX.php List] Filling a multi-dimensional array

DC dan.cynosure at dbmscan.com
Tue Sep 9 13:41:21 MDT 2008


well, "the structure i created" gives you an array with all the values 
in it which was what you requested help on. ;-)

but, when you say "process" it sounds like you want to take FX data 
array and turn it from a recordset array into a columnset array so you 
can use it easily in a menu or something?

maybe this is what you are looking for:
---------------------------------
$i=0;
$additionalParameters= array();
foreach($findResult2['data'] as $record)
     {
	foreach($record as $fieldname=>$field)
	{
   	  $additionalParameters[$i][$fieldname] => $field[0]);
	}
	$i++;
     }
----------------------------------
that assumes you don't have any related fields.

this code does two things to the raw FX data array:

1) flattens it so there are no nested arrays at the lowest level (FX has 
a parameter for this, so you really might enjoy a read through the 
manual. :-)

2) removes the modid and recid keys and replaces them with numeric keys 
for easier array manipulation.

dan

Jonathan Schwartz wrote:
> Think maybe I had not explained myself adequately.
> 
> I need to process a *variable* number of "records", each one containing 
> a field name and a value.  "Year" and "Status" was just an example of 
> using 2 pairs. It could be...
> 
> Year = 2008
> Status = active
> Gender = M
> Grade = 10
> etc.....
> 
> Now...perhaps the structure you created is the best one.  If so, how do 
> I parse the multidimensional array below to extract the pairs?
> 
> Array
> (
>     [0] => Array
>         (
>             [status] => active
>         )
> 
>     [1] => Array
>         (
>             [year] => 2008
>         )
> )
> 
> J
> 
> 
> At 2:59 PM -0400 9/9/08, DC wrote:
>> ha ha ha! you're like that client who changes the spec in the middle 
>> of the project.
>>
>> you must have taken the line i sent and pasted it in TWICE to get the 
>> result you showed. that is, you asked for something with one paramkey 
>> and paramvalue,
>>
>> $additionalParameters= array($value2['paramkey'][0] => 
>> $value2['paramvalue'][0]);
>>
>> but you actually required two paramkeys and two values. steve winter's 
>> should work for you - his working spec: two paramkeys, two paramvalues 
>> per nested array.
>>
>> glad you solved it anyway!
>> dan
>>
>> Jonathan Schwartz wrote:
>>> Thanks DC.
>>>
>>> Although this does build an array with each record, it isn't the type 
>>> of array structure I was expecting .
>>>
>>> I was looking for this result:
>>>
>>> Array
>>> (
>>>       [year] => 2008
>>>         [status] => active
>>> )
>>>
>>> I got this result:
>>>
>>> Array
>>> (
>>>     [0] => Array
>>>         (
>>>             [status] => active
>>>         )
>>>
>>>     [1] => Array
>>>         (
>>>             [year] => 2008
>>>         )
>>> )
>>>
>>>
>>> Jonathan
>>>
>>>
>>>
>>> At 1:32 PM -0400 9/9/08, DC wrote:
>>>
>>>> $additionalParameters[]= array($value2['paramkey'][0] => 
>>>> $value2['paramvalue'][0]);
>>>>
>>>> Jonathan Schwartz wrote:
>>>>> Apologies ahead of time for asking this RTM question, but I need to 
>>>>> get this worked at ASAP.
>>>>>
>>>>> I need to populate a multi-dimenisional array from an FMP query. 
>>>>> The existing code, below, populates only the last record. What 
>>>>> syntax build the array with all found values?
>>>>>
>>>>>
>>>>> $additionalParameters= array();
>>>>>     foreach($findResult2['data'] as $key => $value2)
>>>>>     {
>>>>>     $additionalParameters= array($value2['paramkey'][0] => 
>>>>> $value2['paramvalue'][0]);
>>>>>     }
>>>>>
>>>>>
>>>>> Thanks
>>>>>
>>>>> J
>>>> _______________________________________________
>>>> FX.php_List mailing list
>>>> FX.php_List at mail.iviking.org
>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>
>>>
>>> -- 
>>>
>>> Jonathan Schwartz
>>> Exit 445 Group
>>> jonathan at exit445.com
>>> http://www.exit445.com
>>> 415-370-5011
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> FX.php_List mailing list
>>> FX.php_List at mail.iviking.org
>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
> 
> 


More information about the FX.php_List mailing list