Mythic Fr0st Posted December 17, 2006 Share Posted December 17, 2006 Ok, I have a uhh 'weaponlist' now for my game, when you equip it, it runs weaponlist and checks if each array in weaponlist is equal to the selected item from the drop down box...it works, but I also want to add it so it checks if the second dimension array, is true or false (1,0)I think I can do that, but I need to know how to create an array like it...$weaponlist=array('Iron Dagger','Iron Sword','Steel Sword','Titan Sword');how would I make a double array from thati've tried $weaponlist=array('Iron Dagger','Iron Sword','Steel Sword','Titan Sword'),(1,0,0,0); etc.. but I cant get itif not possible a string array and then numerical value, perhaps just another string? Link to comment https://forums.phpfreaks.com/topic/30937-multi-dimensional-array-holding-a-string-and-a-boolean-value/ Share on other sites More sharing options...
kenrbnsn Posted December 17, 2006 Share Posted December 17, 2006 Actually, I think you want to use an associative array. I'm assuming that you want each item in the array to have the value of true or false.First create the array with all values equal to false:[code]<?php$weaponlist = array('Iron Dagger'=>false, 'Iron Sword'=>false, 'Steel Sword'=>false, 'Titan Sword' => false);?>[/code]The when you want to set one of the entries to "true", you would do:[code]<?php$weaponlist['Iron Dagger'] = true;?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/30937-multi-dimensional-array-holding-a-string-and-a-boolean-value/#findComment-142736 Share on other sites More sharing options...
Mythic Fr0st Posted December 17, 2006 Author Share Posted December 17, 2006 Thanks, that worked, however I cant seem to get the thing to actually work (the string works)this is what im trying to do[code=php:0]if (isset($_POST['eq1'])) { if ($_POST['eq1']=='eq2') { if (isset($_POST['inv'])) { $x=$_POST['inv']; foreach ($weaponlist as $is => $q) { if ($q == $inv[$x]) { if ($weaponlist[$x]==true) { $weaponlist[$x]=false; $wdmg=$weapondmg[$x]; $weapon=$q; echo 'set'; } else { $weaponlist[$x]=true; $wdmg=0; $weapon='Fists'; echo 'unset <br />'; } } } } } }[/code]Im not sure how to do thiscould I doif $weaponlist[$x][$x] or use 2? i tried it but it didnt work(I cant use $weapon['iron dagger'] == true, because I dont know what it is yet, so I use $x and so onbtw is it possible to do even 4 lots?so 'Name of Item' 'item damage' 'item price' 'true'it seems whenever I echo $weapon[$x] it returns 0 or 1erm is that more readable to you??? (I dont know how to indent properly:P) Link to comment https://forums.phpfreaks.com/topic/30937-multi-dimensional-array-holding-a-string-and-a-boolean-value/#findComment-142758 Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 Sorry, but have you ever heard of indentation? I can't read your code AT ALL. Link to comment https://forums.phpfreaks.com/topic/30937-multi-dimensional-array-holding-a-string-and-a-boolean-value/#findComment-142769 Share on other sites More sharing options...
Mythic Fr0st Posted December 17, 2006 Author Share Posted December 17, 2006 mm, ok gime a sec (I use text doc, so I dont really indent:P) i'll indent it Link to comment https://forums.phpfreaks.com/topic/30937-multi-dimensional-array-holding-a-string-and-a-boolean-value/#findComment-142772 Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 Hehe... now none of your indentation lines up. Nice try though. Link to comment https://forums.phpfreaks.com/topic/30937-multi-dimensional-array-holding-a-string-and-a-boolean-value/#findComment-142775 Share on other sites More sharing options...
Mythic Fr0st Posted December 17, 2006 Author Share Posted December 17, 2006 Erm, how are they suppost to be?? LOL like ALL of it but the first and last to be 4 indents or something? Link to comment https://forums.phpfreaks.com/topic/30937-multi-dimensional-array-holding-a-string-and-a-boolean-value/#findComment-142804 Share on other sites More sharing options...
artacus Posted December 17, 2006 Share Posted December 17, 2006 Ok I'm not even going to try to make sense of your codein your foreachforeach ($weaponlist as $is => $q){$is //Iron Dagger$q //true Link to comment https://forums.phpfreaks.com/topic/30937-multi-dimensional-array-holding-a-string-and-a-boolean-value/#findComment-142829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.