Jump to content

taking a delimited list and putting it into an array


mongoose00318

Recommended Posts

Hi all!

 

Ok I am trying to put a delimited list like so , EX. item qty, item name, item price | item qty, item name, item price | item qty, item name, item price | etc. into an array so I can access it like this - $product[0] = qty, $product[1] = name, etc. My code just isnt working. This is what I have so far.

 

				$prod = array();
			//breaking products text down for display
			$products1 = explode("|", $products);
			$num_prod1 = count($products1);
			$count = 0;
			foreach($products1 as $p) {
				$prod[] = $p;
				$products2 = explode(",", $p);
				foreach($products2 as $p2) {
					$prod[$count] = $prod[$count][$p2];
				}
				$count++;
			}

				foreach($products1 as $p) {
				$products2 = explode(",", $p);
				$count = 1;
				foreach($products2 as $p2) {
					if($count <= 2) {
						echo $p2." | ";
						$count++;
					}
					else {
						echo $p2."<br>";
						$count = 1;
					}
				}
			}

 

That code above successfully processes the delimited list I have, is there a way I can modify that to make the array I need? Any advice would be helpful! Thanks alot!

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.