Reputation: 492
I have the following php code, post values are taken from a form-
<?php
$file="data.xml";
$test= new SimpleXMLElement($file, null, true);
echo $_POST['question1'];
echo $test->easy->question[0]->key;
echo $test->easy->question[$_POST['question1']]->key;
Output: 0 3
I am able to get the output for echo $_POST['question1'];
also for echo $test->easy->question[0]->key[0];
. But not for echo $test->easy->question[$_POST['question1']]->key[0];
What am I doing wrong here ?
Upvotes: 0
Views: 55
Reputation: 7603
You could try converting your $_POST['question1']
string into an int
by doing something like this:
$_POST['question1'] = (int)$_POST['question1'];
Upvotes: 0
Reputation: 98559
$_POST['question1']
probably contains a string, '0'
. This is not necessarily the same as the number zero (0
).
Upvotes: 1