Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 4 years ago.
Improve this question
why the OpenServer displays the code in a string but not in the column as indicated in the light image. I do everything the same, but I have everything on the line?
please help me, what am I doing wrong?
this is my code:
and this is my output and all one line:
but it should be like this[original of the required output]
You have var_dump($x) in there two times, which will display the array as a string like in your image. But the echo $x[0] is displayed/echoed correctly in between those two - as "18".
If you want to echo all values of the array, you need a foreach loop, like
foreach($array as $value) {
echo "<p>".$value."</p>";
}
EDIT AFTER COMMENT:
Put the arrays into pre tags and use print_r($x); instead of var_dump($x), like
<pre>print_r($x);</pre>
Related
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 3 years ago.
Improve this question
I am trying to run
$var = "Guru & Hari - Priya";
if(preg_match('/^[A-Za-z0-9& -]+$/', $var)){
echo "Hi";
}else{
echo "bye";
}
Somehow code is unable to understand "&".
Per regex101.com above code is fine.
Please share why PHP is unable to recogonise &
not-an-answer
You should mention/consider your string source.
What you see as & is probably & in your text value.
The browser rendition is not always an exact representation of your data.
See also: PHP Regex: Matching Ands - & and &
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 4 years ago.
Improve this question
I'm trying to add two $_POST variables, like so:
$points = $_POST['old_points'] + $_POST['new_points'];
(Line 48)
Which works fine, except it produces the following error:
Notice: A non well formed numeric value encountered in F:\xampp\htdocs\test\index.php on line 48
I can't figure out what the problem is here.
may be you need convert the content of $post as a correct number
$points = floatval($_POST['old_points']) + floatval($_POST['new_points']);
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 4 years ago.
Improve this question
I have a field in one of my database tables, a sample of this field looks like so ; ["1","4","7"]. Those are keys to a reference in another table. What i want to do is fetch the field and ideally loop through the values and get the data from the referenced table. As you will notice, ["1","4","7"] is PHP declaration for an array but for the life of me, I am unable to parse it as an array. How do i parse it as an array? What am I missing?
You should be able to decode and convert it into an array with PHP's json_decode function.
Example:
<?php
echo '<pre>';
print_r(json_decode('["1","4","7"]'));
echo '</pre>';
?>
If I understood your problem is that your database column store a string PHP array representation.
So you should use the function json_decode
By the way it's a strange way to store relation in a database
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 7 years ago.
Improve this question
Hi I'm totally new here and with and would glad if someone could help as I'm stuck with how I can create a loop with some php code.
$TotalUniques = $this->TotalUniquesHits($Counts[$xx]['ID']);
The value I'm after is [$xx] which represents a position in the array. How to change it so that I get $TotalUniques looping through all the values of $xx?
You can try with foreach loop:
foreach($Counts as $xx){
$TotalUniques[] = $this->TotalUniquesHits($xx['ID']);
}
You may also consider checking if each $xx has ID key with isset or array_key_exists.
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
I pass a variable called txt from one query on a web page to another web page using
<?php echo $_GET['txt'];?>
the problem some time the text will have a word like don't in it. the (') causes things to just stop. I need to output the variable as read from the database which would include any text that was in the field
When using $_GET you should use urlencode() and urldecode().