0
$rowA=array("-1","1","2","-2","3","-3","4");
$rowA['charge']= preg_replace("\-\1", " ", $rowA);

How do i make this such that all numbers show up without negative signs on them? I also want "1" to be omitted from all results. So my results should only be 2,3 & 4 if i access the array.

3
Contributors
4
Replies
12
Views
3 Years
Discussion Span
Last Post by Edwin_2
0

Is there a reason you want to use preg_replace?

$rowB = array ();
foreach ($rowA as $number)
{
    if (abs($number) == 1) continue;
    $rowB[] = abs($number);
}
0

oops, should have asked did you want 2,3,4 or 2,2,3,3,4 ?
(prompted by pritaeas's code).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.