Hard understanding 'echo' from associative array structure [closed] - php

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
So, I get this assoc array structure :
pastebin.com/9nEGKsK0
How can I fetch the urls by 'foreach'?
Help.

You can try this:
<?php foreach($array['response']['items'] as $item) {
foreach($item['sizes'] as $size) {
echo $size['url'];
}
}

echo '<pre>';
print_r($array);
echo '</pre>';

Related

Pass php value to html [closed]

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 1 year ago.
Improve this question
I am trying to pass a simple php value to html but I cannot format it in the right way. How can I do this?
<?php
$html = '
<img src="'$val'.svg" alt="15"> //Does not work
';
$val = 5;
?>
You would try to format it this way:
<?php
$val = 5;
$html = "<img src='${val}.svg' alt='15'> ";
?>

How can I get a single value from jsonp php [closed]

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 2 years ago.
Improve this question
Please can anyone help me out, I've done an API Call and I need to get a single value from the response, as response comes with jsonp.
jsonp ({"statuscode":"025","RRR":"290007816182","status":"Payment Reference generated"})"
You should get response in a variable and use json_decode function like following :
$response = '{"statuscode":"025","RRR":"290007816182","status":"Payment Reference generated"}';
$result = json_decode($response);
echo $result->statuscode;
echo "<br>";
echo $result->RRR;
echo "<br>";
echo $result->status;

foreach loop in Multidimensional Arrays [closed]

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 5 years ago.
Improve this question
$marks=array(
array(a1,a2,a3),
array(b1,b2,b3),
array(c1,c2,c3)
);
so i want this in foreach loop
example
echo "text-start".$marks[0]."text11".$marks[1]."text22".$marks[2]."text-end";
and result to be:
text-starta1text11a2text22a3text-end
text-startb1text11b2text22b3text-end
text-startc1text11c2text22c3text-end
i tried this but it show a1a2a3 b1b2b3
and i cant add text between them
for($r=0;$r<count($marks);$r++)
{
for($c=0;$c<count($marks[$r]);$c++)
{
echo $marks[$r][$c]."test";
}
echo "111<br>";
}
Basics...
foreach($marks as $marky_marks){
echo "text-start".$marky_marks[0]."text11".$marky_marks[1]."text22".$marky_marks[2]."text-end";
}

Disable errors when getting postal code using ipapi.co [closed]

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 6 years ago.
Improve this question
I'm retrieving the postal code by using -
<?php $pstcde = file_get_contents('https://ipapi.co/'.$_SERVER['REMOTE_ADDR'] . '/postal/'); ?>
It works great but if the postal code is not found, it says, "None". I can't find a way to disable the message.
You can empty the variable if the respond is None. With a simple check.
<?php
$pstcde = file_get_contents('https://ipapi.co/'.$_SERVER['REMOTE_ADDR'] . '/postal/');
if($pstcde === "None")
$pstcde = ""; //Empty string. Or you can use unset($pstcde); if you want to unset the variable.
?>

Add text directly next to PHP variable? [closed]

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 have a variable inside an inline style -
style='color:$custom_color;font-size:$custom_icon_size;'
And am trying to add the letters px directly after the $custom_icon_size. This obviously does not work? Any ideas what is the correct method?
thanks
you need to use {} around your PHP vaariable
style='color:$custom_color;font-size:${custom_icon_size}px;'
Assuming that you're echoing it, you have two options:
echo "style='color:$custom_color;font-size:{$custom_icon_size}px;'";
echo "style='color:" . $custom_color . ";font-size:" . $custom_icon_size . "px;'";
$style = 'color:'.$custom_color.'; font-size: '.$custom_icon_size.'px';
echo 'style="'.$style.'"';

Categories