Error with extra { in PHP elseif statement [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Having trouble locating the problem in this elseif
Code checker suggests an extra } however I cannot find it
if (get_field('job_salary') == "Competitive") {
echo "Competitive";
} elseif (get_field('job_salary') == "P.A") {
echo the_field('job_salary_singular');
} elseif (get_field('job_salary') == "P.A Range"){
echo "£" . the_field('job_salary_range_start') . " - " . thefield('job_salary_range_end');
} elseif (get_field('job_salary') == "Per Day"){
echo "£" . thefield('job_salary_day_rate') == " per day";
} elseif (get_field('job_salary') == "Per Day Range"){
echo "£" . the_field('job_salary_day_range_start') . " - " . the_field('job_salary_day_range_end') . " pd"
}

There is no semi-colon on your last 'echo' line. :) Therefore, the last } appears to be extra.

Related

PHP for loop increment by 100000 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I want to loop through $i which starts from 790000000 and echo every 100000 up to 799999999:
790000000
790100000
790200000
790300000
790400000
...
I tried this code but it didn't work:
for ($i=790000000; $i<=800000000; $i+100000) {
echo $i . '<br>';
}
For loop wrong code, you are missing actual code update as $i+100000 does not update variable. Use $i += 100000 instead.
// Here is problem in your code
for ($i=790000000; $i<=800000000; $i += 100000) {
echo $i . '<br>';
}
Update your loop using += instead of i.
Only using + will not increment your $i variable value.
for ($i=790000000; $i<=800000000; $i+=100000) {
echo $i . '<br>';
}

String Length Issue [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I have four string length statements I am trying to validate,but only two are working.
$name = "mike";
$age = "54";
$city = "Chicago";
$building = "Madadnock";
$lengthOfString1 = strlen ( $name );
echo "String length of 'name' " . $lengthOfString1 . "</br>";
$lengthOfString2 = strlen ( $age );
echo "String length of 'age' " . $lengthOfString2 . "</br>";
$lengthOfString3 = strlen ( $city );
echo "String length of 'city' " . $lengthOfstring3 . "</br>";
$lengthOfString4 = strlen ( $building );
echo "String length of 'building' " . $lengthOfstring4 . "</br>";
The top two are the only ones that work. Any help would be great!
variables in PHP are case sensitive
$lengthOfString4 vs $lengthOfstring4
^ ^
The problem lies in variable names. The variable names in PHP are case-sensitive.
$lengthOfString3 = strlen ( $city );
echo "String length of 'city' " . $lengthOfString3 . "</br>";
$lengthOfString4 = strlen ( $building );
echo "String length of 'building' " . $lengthOfString4 . "</br>";
Fixed it.

Resolve PHP post string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have the following post string:
Name=John&Age=33&Question1=What's+your+gender%3F&Answer1=Male&Question2=What's
+your+education%3F&Answer2=Graduate
I'm going to have randomly generated amount of questions each time so I won't be able to know number of passed variables. Thus, I am searching for a solution something like:
foreach($postItem as $varr) {
echo $varr["name"].": ".$varr["value"]."<br />";
}
Post them as answer[1], answer[2] etc instead of answer1, answer2, and PHP will turn them into an array for you.
//parse query string to an array ($output)
parse_str($postString, $output);
echo $output['Name'] . ': ' . $output['Age'] . '<br />';
//process questions
$i = 1;
while (array_key_exists('Question' . $i, $output)) {
echo $output['Question' . $i] . ': ' . $output['Answer' . $i] . '<br />';
$i++;
}
function used http://php.net/parse_str

Php operator `break` doesn't stop while [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Have a weird issue, break doesn't break while loop and keep rotating. Logically it should break the cycle and I set some output
while ($c++ != 5)
{
// here is curl request, doesn't relevant so I have removed it
preg_match("!<.*?>(\S*)[^<>]*?{$to}<!", $resp, $result) ;
//
echo 'cnt = ' .count($result).'<br>';
if(!count($result))
{
$amount = 0;
echo 'sleep called';
sleep(4);
exit;
continue;
}
else
{
$amount = trim(#$result[1]);
$amount = round($amount + $amount * $exchange_ratio, $precision);
echo 'break happen<br>';
break;
}
}
so output is
cnt = 2
break happen
cnt = 0
sleep called
So it skipped break and keep rotating. How so?
EDIT
works fine on my localhost so issue probably with php version?
You must be running this code multiple times: is there a second call to this script, or a second loop around this part? Look at my test code: it clearly breaks after the break:
$ cat tmp.php
<?php
$c = 0;
while ($c++ != 5)
{
if(false) //just emulating you
{
$amount = 0;
echo 'sleep called';
sleep(4);
exit;
continue; //this will never be called by the way
}
else
{
echo 'break happen<br>';
break; //this indeed breaks out of the while
}
}
$ php tmp.php
break happen<br>$
(the $ is the next prompt, on the same line as I did not put in a newline :) )

If within Switch - Case in php [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am trying to create a query from the data i receive from an array of objects in php. I keep receiving an error on the nested if inside a case. unexpected '{', is it because I can't have an if within a case?
switch($name){
case 'players':
$query .= " min_players <=".$value." AND max_players >=".$value." AND";
break;
case 'max-duration':
if((intval($value) >= 45) {
$min = intval($value)-30;
$query .= " duration <=".$value." AND duration >=".$min." AND";
} else { //if duration < 45
$query .= " duration <=".$value." AND";
}//end else
break;
}
switch($name){
case 'players':
$query .= " min_players <=".$value." AND max_players >=".$value." AND";
break;
case 'max-duration':
if((intval($value)) >= 45) {
$min = intval($value)-30;
$query .= " duration <=".$value." AND duration >=".$min." AND";
} else { //if duration < 45
$query .= " duration <=".$value." AND";
}//end else
break;
}
You had to add a ) after
if((intval($value)

Categories