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++;
			}

Link to comment
Share on other sites

				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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.