Monkuar Posted March 1, 2012 Share Posted March 1, 2012 $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 Quote Link to comment https://forums.phpfreaks.com/topic/258079-how-do-i-correspond-explodes-into-a-array/ Share on other sites More sharing options...
l0gic Posted March 1, 2012 Share Posted March 1, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/258079-how-do-i-correspond-explodes-into-a-array/#findComment-1322915 Share on other sites More sharing options...
creata.physics Posted March 2, 2012 Share Posted March 2, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/258079-how-do-i-correspond-explodes-into-a-array/#findComment-1323032 Share on other sites More sharing options...
dragon_sa Posted March 2, 2012 Share Posted March 2, 2012 I would use a table called styles and store the information for each style there, and just call upon it when you want it, can easily be modified, and can easily be kept unified across the whole site Quote Link to comment https://forums.phpfreaks.com/topic/258079-how-do-i-correspond-explodes-into-a-array/#findComment-1323066 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.