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
foreach ($result as $key => $value) {
}
In this can the $value be an object like the following given below ,
where 10 is the key and other is value
[10] => stdClass Object
(
[nid] => 80
[type] => create_an_account
)
Is this valid ??
I would love to make a long answer but I can't develop more than: Yes it is. For your culture, this is extract from the foreach doc:
The foreach construct provides an easy way to iterate over arrays. foreach works only on arrays and objects, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable. There are two syntaxes:
Before asking on SO, you can try by yourself :)
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 8 years ago.
Improve this question
I want to compare each digit of a number array. Like: 5450...i want to compare each of the digit such as: 5,4,5,0 individually with other number.for that i want to convert this number string in number array.how to do this?
you can use str_split to convert the string in to Array
For example:
<?php
$str="5450";
$arr=str_split($str);
print_r($arr);
?>
output:
Array ( [0] => 5 [1] => 4 [2] => 5 [3] => 0 )
You can use preg-split - see example two here: http://us3.php.net/manual/en/function.preg-split.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
Hello I had a link...
'process.php?wpn=somevaluehere'
Where I want whatever value place on 'wpn' must get another value from array of values example.
array (
"somevaluehere" => 5,
"somevalue10" => 10,
"somevalue20" => 20
);
then how I can output the array values, been trying to search over google but I failed to find it since I am very new PHP programmer but I learn pretty fast and somehow can understand them. And if it can't be found on the array list, I wish it do nothing.
$values = array(
"somevaluehere" => 5,
"somevalue10" => 10,
"somevalue20" => 20
);
echo $values[$_GET['wpn']];
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
This is the array: http://www.stylechica.de/array.rtf (I can't copy it here)
I need to sum up ["PriceInformation"]["PriceInformation"]["PriceDetails"]["Price"] and allready tryed all kind of stuff like
foreach ($output["PriceInformation"]["PriceDetails"]["Price"] as $product)
echo array_sum($product);
but it just won't work. Any ideas?
Because $product refers to each iteration of $output["PriceInformation"]["PriceDetails"]["Price"], you can't sum the entire array like this. The best way to do it would be to add it to a variable as you go:
$your_sum = 0;
foreach($output as $value) {
$your_sum += $value['PriceInformation']['PriceDetails']['Price'];
}
echo 'Sum: ' . $your_sum;
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
If I have an array with identifiers like this "name" => "Manoel", "age" => 45 then how can I turn them into individual variables without having to know each identifier in the array? is it possible?
Can I do that inside a class to create new properties?
Thanks.
Try this:
<?php
$Wales = 'Swansea \n';
print $Wales;
$capitalcities['England'] = 'London';
$capitalcities['Scotland'] = 'Edinburgh';
$capitalcities['Wales'] = 'Cardiff';
extract($capitalcities);
print $Wales;
?>
The result you should see in your browser is:
Swansea
Cardiff
And yes, if you do this inside an object you may have those variables as properties in execution time.
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 array:
array(
(int) 1 => 'igor.cesar#soreq.com.br',
(int) 5 => 'igorpol#gmail.com',
(int) 6 => 'kkk#asasa.com'
)
I want to convert to this:
array('igor.cesar#soreq.com.br','igorpol#gmail.com','kkk#asasa.com')
How can I do this?
You could use the array_values function:
array_values($yourarray);
i would do it like this.
foreach($yourArray as $v)
{
$newArray[]=$v;
}
explanation
for each value of your array put it in a new array called $newArray