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 2 years ago.
Improve this question
I have
$div = 100
$value = 502
$sum = $val / $div
how can i get output like this
100
100
100
100
100
2
any reffrence to learn more?
Here's one way to do it:
$div = 100;
$value = 502;
while($value > $div) {
$value = $value - $div;
echo $div . "<br>";
}
echo $value
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 2 years ago.
Improve this question
I want split one group AS follow
splitGroups("11133355557777") ➞ ["111", "333", "5555", "7777"]
Anyone have idea then let me know
With php version 5 above this will work link to execute
Link to an example https://paiza.io/projects/qfRZ07OP3OviWCVsUbdFtQ
function splitGroups($str){
$arr = [];
$i=0;
$sub = '';
while($i!=strlen($str))
{
$sub .= $str[$i];
if ( strlen($str)-1 == $i || $str[$i] != $str[$i+1] ){
$arr[] = $sub;
$sub='';
}
$i++;
}
return $arr;
}
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 2 years ago.
Improve this question
I want to use a loop to iterate through my array, calling my function to print out all of these messages. I have to somehow keep track - I'm using PHP code.
This my code :
<? php
$count = 6;
$rp = 11000;
$amount = array(1000,1000,1500,500,2000,4000);
foreach ($amount as $v) {
echo $total = $rp-$v; ?>
my output should be:
10000
9000
7500
7000
5000
1000
Is this what you want?
<?php
$count = 6;
$rp = 11000;
$amount = array(1000,1000,1500,500,2000,4000);
foreach ($amount as $v) {
$rp = $rp - $v;
$count--;
//echo $count;
echo $rp."<br/>" ;
}
?>
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 2 years ago.
Improve this question
I need your help to get the position of duplicate or same elements in an array.
For example
$arr =[6,5,3,7,40,45,7,6,3,32,86,40,5,3,7,40];
Result
6 = 0,7
5 = 1,11
3 = 2,8
7 = 3,6,14
40 = 4,11,15
45 =5 and so on.
One simple approach:
<?php
$arr =[6,5,3,7,40,45,7,6,3,32,86,40,5,3,7,40];
$pos = array();
foreach($arr as $k => $v) {
$pos[$v][] = $k;
}
foreach($pos as $k => $v) {
echo $k."=".implode(',', $v)."<br>";
}
?>
Result:
6=0,7
5=1,12
3=2,8,13
7=3,6,14
40=4,11,15
45=5
32=9
86=10
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 6 years ago.
Improve this question
How to replace 200 numbers with an image?
This example :
For example
When user have 200 numbers He takes 1 image
When user have 830 He take 4 image
what php code I need it?
Sorry but I havn't Any code
Thanks in advance
$votes = 10334;
$starCount = intval($votes/ 200);
$starCount = $starCount > 5 ? 5 : $starCount; //if maximum 5 stars
$a = 1;
$starsString = '';
for ($a; $a <= $starCount; $a++) {
$starsString .= '⛤'; // or '<img src="https://i.stack.imgur.com/EhAy4.gif" alt="here">'
}
echo $starsString;
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 6 years ago.
Improve this question
I have this array`
<?php
$arr = [['name'=>'john','age'=>20,'sex'=>'m'],
['name'=>'maria','age'=>12,'sex'=>'f'],
['name'=>'nick','age'=>25,'sex'=>'m'],
['name'=>'jo','age'=>31,'sex'=>'f'],];
foreach ($arr as $persoana) {
foreach ($persoana as $id=>$value) {
if ($id == 'age') {
$sumvarsta = $sumvarsta + $value;
$n++;
}
}
}`?>
i need total average age (total average age seems to be working ok) , average age for women and average age for men.
How to calculate ?
thx.
<?php
$arr = [['name'=>'john','age'=>20,'sex'=>'m'],
['name'=>'maria','age'=>12,'sex'=>'f'],
['name'=>'nick','age'=>25,'sex'=>'m'],
['name'=>'jo','age'=>31,'sex'=>'f'],];
$womansum = 0;
$womancount = 0;
$mansum = 0;
$mancount = 0;
foreach ($arr as $persoana) {
if ($persoana['sex'] == 'm')
{
$mansum += $persoana['age'];
$mancount++;
} else {
$womansum += $persoana['age'];
$womancount++;
}
}
$manAverage = $mansum / $mancount;
$womanAverage = $womansum / $womancount;
$totalAverage = ($mansum + $womansum) / ($mancount + $womancount);
?>