Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Why can't I call this function with the function and increment it's argument?
It seems to loop endlessly without $i incrementing.
function loopy($i) {
loopy($i+1);
echo $i.'...';
if ($i >=5) return true;
}
Because the if statement needs to go before calling the function again to stop it beign an infinite loop:
function loopy($i) {
if ($i >=5) return true;
loopy($i+1);
echo $i.'...';
}
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Just need help fixing this php code
if ($cmtx_set_name_value == "anonymous")
{
$cmtx_set_name_value = ""
}
thanks
Try adding ; after the assignment.
$cmtx_set_name_value = "";
your code is work fine just put ; to end of line
if ($cmtx_set_name_value == "anonymous"){
$cmtx_set_name_value = "" ; }
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I receive data in this format like:
C00001,C00302,C00303,C00287,C00286,C00285,C00017
in a variable but i need in this shape:
'C00001','C00302','C00303','C00287','C00286','C00285','C00017'
i am new in mysql kindly any help
You can explode the data, modify it, then re-implode it.
$data = 'C00001,C00302,C00303,C00287,C00286,C00285,C00017';
$arr = explode(',', $data);
$new_arr = array_map(function($a){
return "'{$a}'";
}, $arr);
$new_data = implode(',', $new_arr);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am struggling to get pull the correct values
I am trying to get the following
packages>items then loop through the ids
{"id":1,"title":"Barnsley","slug":"barnsley","packages":[{"id":1,"title":"Group PACKAGE 1","items"
{"id":9,"title":"Guiness","band_a":null,"band_b":null,"band_c":null,"band_d":null,"band_e":null,"band_f":null,"band_g":null,"band_h":null,"band_i":null,"band_j":null,"variations":null},
{"id":10,"title":"John Smith","band_a":null,"band_b":null,"band_c":null,"band_d":null,"band_e":null,"band_f":null,"band_g":null,"band_h":null,"band_i":null,"band_j":null,"variations":null},
{"id":22,"title":"Chicken Cheese and Bacon Melt","band_a":4.5,"band_b":4.75,"band_c":5.0,"band_d":5.25,"band_e":null,"band_f":null,"band_g":null,"band_h":null,"band_i":null,"band_j":null,"variations":null}],"additional_items":null,"event_types":null}]}
Your JSON isn't valid. You're missing two characters :[ that declare the items array. After fixing the JSON (check it on jsonlint.com) you can iterate over the item IDs like so:
$obj = json_decode($str);
foreach($obj->packages[0]->items as $item)
{
echo $item->id;
}
If there could be more than one package you can iterate those too:
foreach($obj->packages as $package)
{
foreach($package->items as $item)
{
echo $item->id;
}
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to set the class hidden, unless two factors are met. Currently, I'm using the code below:
<?php
if (isset($_POST['prerequisite']) && $form == "CheckingIn")
{
}
else
{
echo "hidden";
}
?>
How can I fix this to just be an if statement instead of an if/else?
Negate the expression; use the "NOT" logical operator:
if (!(isset($_POST['prerequisite']) && $form == "CheckingIn")) { echo "hidden"; }
(notice the ! symbol)
Read more here: http://php.net/manual/en/language.operators.logical.php
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
The simple program is not returning the string,Please help.
<?php
function returnStr() {
return "fooBar";
}
$str=returnStr();
echo $str;
}
?>
It's a parse error:
$str=returnStr();
echo $str;
} // WHAT IS THIS BRACKET DOING HERE?
There's a fatal error tokenizing the code due the trailing/unmatched '}' remove that and the code will work. Then spend some time thinking about why you didn't know this already
There's an error in your code. The last } is useless.