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 have this PHP code that displays values in an array:
$header->from[0]->mailbox . "#" . $header->from[0]->host;
whats the best way to loop round to get [1], [2], [3], etc...
You can do it through a foreach loop like this:
foreach ($header->from as $from){
echo $from->mailbox . "#" . $from->host;
}
If you want to process the first element outside the loop, then you can use array_shift:
$first_from = array_shift($header->from);
$first_from->mailbox . "#" . $first_from->host;
foreach ($header->from as $from){
echo $from->mailbox . "#" . $from->host;
}
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
Can anyone help me get the value of IFC/USD 0.00001031 from the webpage http://infinitecoin.com.
I need to grab the value after IFC/USD..
The way I thought to do it was to:
$file_string = file_get_contents('http://infinitecoin.com');
preg_match('/IFC/USD plus next 11 charecters', $file_string, $title);
$value = $title[1];
echo $title_out ;
But im not sure how to ask PHP to find IFC/USD then return the next 11 characters after that.
If I could accomplish this, my task would be solved..
Any help would be great.
Thank you
Jason
$output = array();
preg_match("/(?<=IFC\/USD\s)[\d\.]+/", 'IFC/USD 0.00001015', $output);
$output will look like this:
Array
(
[0] => 0.00001015
)
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 have the following code and output
for ($i=0;$i<=100;$i++)
if ($i % 2!=0)
echo $i + "";
?>
13579111315171921232527293133353739414345474951535557596163656769717375777981838587899193959799
The problem is that there is no space between the numbers. How do I add this space
Change echo $i + ""; to echo $i . " ";
for ($i=0;$i<=100;$i++)
if ($i % 2!=0)
echo "$i ";
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 8 years ago.
Improve this question
Here's the scenario, I have a form that contains checkboxes and when submitted will be sent to a certain email. I am trying to put the checked items into one string. Like option1 option2 option 3
Here is what I have done for now:
echo $message = foreach($_POST['checkbox'] as $checkbox){ echo $checkbox . "\r\n";}
Desired output of $message:
Option1
Option2
Option3
Please make it as:
$message = '';
if (! empty($_POST['checkbox'])) {
foreach($_POST['checkbox'] as $checkbox) {
$message .= $checkbox . "\r\n";
}
}