Jump to content

Multi-Dimensional array holding a string and a boolean value


Mythic Fr0st

Recommended Posts

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 that
i've tried $weaponlist=array('Iron Dagger','Iron Sword','Steel Sword','Titan Sword'),(1,0,0,0); etc.. but I cant get it

if not possible a string array and then numerical value, perhaps just another string?
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
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 this

could I do

if $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 on

btw 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 1

erm is that more readable to you??? (I dont know how to indent properly:P)

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.