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
Could PHP check if a certain element in the array contains some words?
for example :
`[order_product_code] => I9300_cash397096569`
want to check if the element contains cash word.
If $array is your array of element:
foreach($array as $key=>$element) {
if(strpos('cash',$element) !== FALSE) echo "$key: ok";
else echo "$key: ko";
}
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 have this string
$string = "Social\Notify\Models\User";
How can i tell to php how select just the fourth segment of it? in this case just the word User?
Something like this will do?
$str='Social\Notify\Models\User';
echo explode('\\',$str)[3]; //"prints" User
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
My code is as follows:
for($i=0;$i<=100;$i++){
echo $i."<br>";
}
and the output I got is:
0<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<br>11<br>12<br>13<br>14<br>15<br>16<br>17<br>18<br>19<br>20<br>21<br>22<br>23<br>24<br>25<br>26<br>27<br>28<br>29<br>30<br>31<br>32<br>33<br>34<br>35<br>36<br>37<br>38<br>39<br>40<br>41<br>42<br>43<br>44<br>45<br>46<br>47<br>48<br>49<br>50<br>51<br>52<br>53<br>54<br>55<br>56<br>57<br>58<br>59<br>60<br>61<br>62<br>63<br>64<br>65<br>66<br>67<br>68<br>69<br>70<br>71<br>72<br>73<br>74<br>75<br>76<br>77<br>78<br>79<br>80<br>81<br>82<br>83<br>84<br>85<br>86<br>87<br>88<br>89<br>90<br>91<br>92<br>93<br>94<br>95<br>96<br>97<br>98<br>99<br>100<br><!DOCTYPE html>
Why this thing is happening:
This is happening because that is what you have programmed. Echo does not auto-append a newline, nor does using <BR>.
Change your code to include a newline:
for($i=0;$i<=100;$i++){
echo $i."<br>\n";
}
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
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
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 having trouble creating a PHP code that does the following scenarios,
Each of the 4 kids in the group have to eat 3 fruits. Once a kid eats 3 fruits, he has to be removed for the group and so on until the group is empty.
$kids = array('Bob', 'Joe', 'Sue', 'Sara');
foreach ($kids as $key => $kid)
{
for($i=1; $i<=3; $i++)
{
eat_fruit($kid);
}
// drop kid from kids
unset($kids[$key]);
}