Hello,
Summary:
I push numbers to array, then when I use implode and it works fine
But if I add quotes to these numbers (which I need), implode will throw zeros instead of my numbers
More details:
I have an array of numbers (initially when I get some info from DB, it is without any quotes, when I push values to "$values" array):
array_push ($values, $number); // $number is one element from DB
Array will look like this (no quotes):
array(123, 2765, 143, 187);
So when I use - echo implode(',',$values); it looks like this: "123, 2765, 143, 187"
I need to add single quotes around these numbers (but this is not the problem)
array_push($values, "'" . $number . "'"); // Adding quotes, also tried adding quotes before pushing to array
Now, if I print each element of array, it will be with quotes as I want it to be:
'123'
'2765'
...
But here is a problem:
echo implode(',',$values);
Relult is all zeros
0,0,0,0,0,0,.....
I've tried many different combination and nothing helped.
Here are some examples:
=======
$number = "'" . $row['value'] . "'";
array_push($values, $str); // added quotes and then pushed
=======
array_push($names, "'" . $number . "'"); // added single quotes
=======
$values[] = "\' . $number . \'"; // tried to escape quotes, since it might confuse implode (',',$numbers);
=======
$values[] = "{$number}"; // This did not help either
=======
Please help!!!
Here is all together:
=======
while ($row = mysql_fetch_array($result)){
array_push($values, "'" . $number . "'");
}
implode(',',$values);
=======
Output:
0,0,0,0,0
Summary:
I push numbers to array, then when I use implode and it works fine
But if I add quotes to these numbers (which I need), implode will throw zeros instead of my numbers
More details:
I have an array of numbers (initially when I get some info from DB, it is without any quotes, when I push values to "$values" array):
array_push ($values, $number); // $number is one element from DB
Array will look like this (no quotes):
array(123, 2765, 143, 187);
So when I use - echo implode(',',$values); it looks like this: "123, 2765, 143, 187"
I need to add single quotes around these numbers (but this is not the problem)
array_push($values, "'" . $number . "'"); // Adding quotes, also tried adding quotes before pushing to array
Now, if I print each element of array, it will be with quotes as I want it to be:
'123'
'2765'
...
But here is a problem:
echo implode(',',$values);
Relult is all zeros
0,0,0,0,0,0,.....
I've tried many different combination and nothing helped.
Here are some examples:
=======
$number = "'" . $row['value'] . "'";
array_push($values, $str); // added quotes and then pushed
=======
array_push($names, "'" . $number . "'"); // added single quotes
=======
$values[] = "\' . $number . \'"; // tried to escape quotes, since it might confuse implode (',',$numbers);
=======
$values[] = "{$number}"; // This did not help either
=======
Please help!!!
Here is all together:
=======
while ($row = mysql_fetch_array($result)){
array_push($values, "'" . $number . "'");
}
implode(',',$values);
=======
Output:
0,0,0,0,0