PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Looking at that it shows taht you have to declare all the variables inside the array. But I do not know how many different variables "$features[]" there are going to be? Am I being stupid or what :S Help ty
You don't know how many are going in? If that's the case, you can always use $features[] when adding, and PHP will automatically add the value to the next index of $array. If you need to know how many elements are going to be in $features before you start reading, you can always use count($features).
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Using $numfeatures = count($features); I get 1 when displaying its value.
Also the explode isnt working.. it is supposed to seperate all the lines with a - but its not, when echo'ing $features it comes out like it is in the database.. ie.. hello 1 - hello 2 - hello 3
EDIT * ROFL i just had to change " - " to "-" in the explode function
$notablefeatures = "this-that-sompn-else-other-than-woohoo";
// note there's no quotes around $noteablefeatures, below
$features = explode('-', $notablefeatures);
echo count($features);
// will print out "7" as there are 7 dash seperated values in the string above
foreach ($features as $feature) {
echo "$feature\n";
}
// will print out
// this
// that
// sompn
// etc...
foreach ($features as $key => $feature) {
echo "$featuresї$key] is the same as $feature\n";
}
for ($i=0; $i<count($features); $i++) {
echo "$featuresї$i]\n";
}
[php_man]foreach[/php_man]() is nice for handling the array data, but if you simply want to look at them (say for investigating GET vars, or whatever); [php_man]print_r[/php_man]() is great.