Jump to content

Associative Array Program issues...


ChadLeedy

Recommended Posts

I'm having trouble with my program...hitting a problem with the While loop and would like any suggestions to clear this up.  Attached is a zipped copy of my code file.  I would like to display a listing in my foreach loop containing each piece of data in my array.  I will also attach the file im using included in my program.  If you need more clarification for what im looking for please let me know.

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/199446-associative-array-program-issues/
Share on other sites

I think you are trying to do something more like:

$temp=explode("\n",$data)

 

Which will get you an array like

$temp[0]="Multiquip_Tamper 2006 MT-75H 85.50 273 23341.5 12297.0 1367 .2 Monthly"

$temp[1]=Emglo_Air_Compressor 2004 K5HGA-8P 109.95 214 23529.3 7335.0 1404 .2 Monthly"

 

Then you can

foreach ($temp as $row){
$temp_array=explode(" ",$data);
$last_temp['name']=$temp_array[0];
$last_temp['year']=$temp_array[1];
$last_temp['serial']=$temp_array[2];
$last_temp['rent']=$temp_array[3];
....
$equipment[]=$last_temp;
}

 

Do a print_r($equipment)

 

The problem with this method, however, is the fact that it will be difficult to reassemble the data, or at least to save the changes.  I mean, sure you can implode the data into a string, but how are you going to save it?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.