Jump to content

How do I correspond explodes into a Array?


Monkuar

Recommended Posts

$stylesbought = explode(",", $user['color2']);
//$user['color2'] is 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  (16 values to correspond at the bottom)


$styles = array(
'Purple Orb' => array('#660099', '#CC99FF', '20.00',''.$stylesbought.''),
'Ms Beautiful' => array('#FFFDB5', '#D391FF', '30.00'),
'Blue Essense' => array('#2B8EFF', '#63CBFF', '50.00'),
'Pink Essence' => array('#FF08FF', '#E01DDA', '100.00'), 
'Mythical Blue' => array('#0066ff', '#3300ff', '150.00'), 
'Green Essence' => array('#39FF08', '#54FF7C', '200.00'), 	
'Leaf Green' => array('#67e03f', '#000000', '250.00'), 		
'Black Essense' => array('#000000', '#000000', '300.00'), 	  
'Pikachu' => array('#F4FF54', '#000000', '400.00'), 
'Charmander' => array('#FF0303', '#000000', '500.00'), 
'Purity' => array('#ffffff', '#ffffff', '520.00'),
'Pink Steel' => array('#ffffff', '#ff00ff', '540.00'), 
'Ice Crystal' => array('#ffffff', '#00ccff', '600.00'), 
'Plated Steel' => array('#ffffff', '#363636', '700.00'),
'Red Steel' => array('#ffffff', '#ff3333', '700.00'),
'The Dark Knight' => array('#000000', '#736f6e', '800.00'),
		  );

 

Okay, so people can buy these styles, let's say somone buys the The Dark knight for 800(Gold), I will update there $user['color2'] to 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1

 

Hence 1 is the 16th one, and the 16th Array, the dark knight is #16 on the array, now, how do I explode that result and make it correspond with my multi demi array so it shows

 

'Purple Orb' => array('#660099', '#CC99FF', '20.00',''.$stylesbought.''),

 

as $stylesbought will mark it at 1 (or bought).

 

So for the purple orb, that is array #0, so my $user['color2'] would look like this:

 

1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1

 

Hence Purple orb is bought.  Now I need to correspond this data to my multi demi array to show the user which styles he has bought.

 

Any help? thx

Link to comment
Share on other sites

I think you want to use implode()?

 

implode(separator,array) 

 

More: http://php.net/manual/en/function.implode.php

 

Sorry didn't read that right!

 

Use a loop to loop through both arrays and update your multi-dimensional one, something like.

 

<?php
$i=0;
while($i < count($styles)) {
  $styles[$i][3] = $stylesbought[$i];
  $i++;
}
?>

 

Above code may not be exact, not on my dev machine right now but hope you can see what I'm trying to do there?

 

 

Link to comment
Share on other sites

Um, you may want to rethink the way you are doing this.

 

I see your styles are put into the script manually, so an admin couldn't add/edit/delete these specific styles unless they modified the code, that is fine, but I'd eventually change that.

 

I would make $user['color2'] capable of handling a good amount of text. I would make an array to store the users colors that s/he has purchased.

// 0 means not purchased, 1 means purchased - also you will need to finish the array on your own 
$userColors = array ('Purple Orb' => 0, 'Ms Beautiful' => 0, 'Blue Essence' => 0 ...... );

 

Then I would serialize the array and keep it stored in $user['color2']

$default_purchases = serialize( $userColors );

 

I'd set that code up upon registration

 

Now when a user goes to purchase, let's say, Purple Orb, we will unserialize the array, update that users Purple Orb value to 1, serialize it once again and update the field in the database.

$userColors = unserialize($user['colors2']); $userColors['Purple Orb'] = 1; $_userColors = serialize($userColors); mysql_query('UPDATE QUERY');

 

Hope that helps

 

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.