change specific values of array in PHP [closed] - php

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.

Related

how to return an INTEGER_ARRAY [closed]

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 5 days ago.
Improve this question
Given an integer, n, determine the following:
How many 1-bits are in its binary representation?
The number n’s binary representation has k significant bits indexed from 1 to k. What are the respective positions of each 1-bit, in ascending order?
The function is expected to return an INTEGER_ARRAY
The function accepts INTEGER n as parameter

PHP: What is the best way to get last even value in array? [closed]

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

How i separate value from array in same line [closed]

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));
}

Generate all possible 4 digit numbers in PHP and concatenate them with a string [closed]

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 6 years ago.
Improve this question
So, I want to generate all possible 4 digit numbers in columns, one by one, (0-9) from 0000 to 9999, and concatenate a string before them, like:
text0000
text0001
text0002
text0003
text0004
text0005
Thanks in advance.
Following will do the trick.
for($i=0;$i<10000;$i++)
echo "text".str_pad ($i,4,'0', STR_PAD_LEFT)."<br />";
$yourString = 'text';
$generateNumberUpTo=9999;
for ($i = 0; $i <= $generateNumberUpTo; $i++)
echo sprintf("$yourString%'.04d<br/>", $i);

check array for limitations [closed]

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 8 years ago.
Improve this question
I am accepting form submissions.
To prevent spoofing of the form I am using php isnumeric to verify that the posted values contain only numeric values.
I would like to check also:
1) that the posted values array contains max 1000 values (because no user would buy more than 1000 items!)
2) that the size of a single array key is composed of max 20 numbers (bigint unsigned max length)
how do I achieve this?
Point 1:
if (count($posted_values) <= 1000)
{
...
}
else
echo "Error";
Point 2:
Did you mean PHP_INT_MAX ?
If yes, just do:
foreach($posted_values as $value)
and then check that $value is less or equal than PHP_INT_MAX.

Categories