$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.

2,3,4 or 2,2,3,4 ?

Is there a reason you want to use preg_replace?

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

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

2,2,3,3,4. That is right.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.