vendredi 27 février 2015

IF ELSEIF fo array inside While loop PHP

I've get the value inside literal tag in this xml:



<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/xml-to-html.xsl"?>
<sparql xmlns="http://ift.tt/1H8JDsT">
<head>
<variable name="Kategori"/>
</head>
<results>
<result>
<binding name="Kategori">
<literal datatype="http://ift.tt/QHQMAU">Gerak Kasar</literal>
</binding>
</result>
<result>
<binding name="Kategori">
<literal datatype="http://ift.tt/QHQMAU">Gerak Halus</literal>
</binding>
</result>
</results>
</sparql>


using this code:



$x = 0;
$kategori = array();
while ($x < count($hasilcek->results->result)) {
$kategori[$x]= $hasilcek->results->result[$x]->binding->literal;
$x++; }


But when I try to get the result by IF ELSEIF inside WHILE using this code:



$x = $x-1;
while ($x > -1){
if ($kategori[$x] = 'Gerak Kasar') {echo "Gerak Kasar";}
elseif ($kategori[$x] = 'Gerak Halus') {echo "Gerak Halus";}
else {echo "tidak ada";}
$x--;}


exactly the result should be:



Gerak Kasar Gerak Halus



but why i get :



Gerak KasarGerak Kasar



I think there is something wrong when I do IF selection for $kategori[] inside the WHILE. Can anyone explain? Thanks.


Aucun commentaire:

Enregistrer un commentaire