Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a function called calculate. And inside the calculate function I have a paramater next to it
function calculate($id){
..
}
What I'm trying to figure out how to do is make a loop which will start the loop and the function calculate will start with the ($id) next to it from 1 to 10. So it does the same thing 10 times with the id set to 1 then 2 then 3 and so on to 10.
Try using range
function calculate($id){
//other statements
// return ;
}
foreach (range(0, 10) as $id) {
calculate($id);
}
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 days ago.
Improve this question
I'm trying to find the sum of numbers by querying a database using PHP and MYSQL. I need a while loop or any other solution that can add numbers that are >= 40 from a sequence of numbers. I'm only able to make the query but don't know how to go about the rest.
$selectMARK="SELECT mark FROM resultstbl WHERE mark >= 40";
$queryMARK=mysqli_query($dbCon, $select);
$sum=0;
while($rowz=mysqli_fetch_assoc($queryMARK))
{
// need some code to add the numbers here
}
You maybe need an
$iterator = 0;
outside the loop, that you can increment inside of it.
$sum += $rowz[$iterator];
$iterator++:
Then do your condition around it by checking $rowz[$iterator] <= 40
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
Suppose , I have a array with some integers value (odd and even both mixed) in php.and I want to get last even number.
A loop that works backwards through the array would work.
$number=false;
$a=array(2,4,5,4,6,7,13,11,95,88,16,17,107);
for($i=count($a)-1; $i >= 0; $i--){
if( $a[$i] % 2 == 0 ){
$number=$a[$i];
break;
}
}
echo $number; //16
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
From web scalping i get array like
1JANATAMF 7.20 -0.10 -1.37%
1STPRIMFMF 11.80 -0.10 -0.84%
AAMRATECH 32.80 0.40 1.23%
and many row.
I want to separate value like 1JANATAMF,7.20,-0.10,-1.37% or insert value to mysql data base by 1JANATAMF as a name and price as 7.20
How can i do this?
Regex: "#\s+#" Here we are matching string on one or more spaces.
Try this code snippet here
<?php
ini_set('display_errors', 1);
$data=array(
"1JANATAMF 7.20 -0.10 -1.37%",
"1STPRIMFMF 11.80 -0.10 -0.84%",
"AAMRATECH 32.80 0.40 1.23%"
);
foreach($data as $value)
{
print_r(preg_split("#\s+#", $value));
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
<?php
$x=6;
$y=9;
$time = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
for ($i=$x;$i<=count($y);$i++)
{
If($x!=$y)
{
$time[$i]=1;
}
}
?>
Depending on the value of x and y,the values in array should change.
In this example... array[5] until array[8] should be value 1.
The value of x and y will not same.
Not a very good question, but I'm a little bored. So for fun:
array_splice($time, $x-1, $y-$x-1, array_fill(0, $y-$x+1, 1));
Not exactly sure of the logic using 6 and 9 and array[5] until array[8] is, but adjust the numbers to fit the range.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
When I print out the integers (1 or 0), all the iterations (there are 3 of them in this case) print out the correct number. First and the second one return 1, the last one returns zero. BUT, 'if' statement seems to display everything in it anyway. What am I doing wrong?
All the code below is inside a bigger 'for' loop.
$yn = 0;
if(!in_array($pos, $blocks)){
$blocks[$x] = $pos;
$x++;
$yn = 1;
}
print_r($blocks);
print "YN: ".$yn; # this prints out 1, 1 and 0 on the last iteration
if(yn){
# show some stuff (is displayed in all three iterations, but it shouldn't be on the last)
}
Try:
if($yn){
PHP is interpreting yn as a string, rather than as the variable you should be using.