2

I have explode here is the result of var_dump:

result of explode

and I want get the result from explode:

7 [remove other string]
0 [if contain "-"]
0 [if contain "-"]
0 [if contain "-"]

Here, I just used comma as delimiter:

var_dump (explode(",", $rowData[0][13]));
die();

Does anyone have the solution to solved this?

Thank You.

3
  • 1
    Hey, instead of adding an image, paste the result of the explode in here. Commented Nov 22, 2018 at 3:29
  • @iagowp here it is : array(4) { [0]=> string(3) "JZ8" [1]=> string(3) " B-" [2]=> string(3) " S-" [3]=> string(3) " M-" } Commented Nov 22, 2018 at 3:31
  • 2
    Also, you should post what have you tried to solve this problem. Commented Nov 22, 2018 at 3:33

2 Answers 2

1

Use array_map() function and in it use filter_var() to sanitize number value.

Try

$rowData = ['JJ7', 'B-', 'S-', 'M-'];

$result = array_map(function($v) { 
    return abs((int) filter_var($v, FILTER_SANITIZE_NUMBER_INT)); 
}, $rowData );

var_dump( $result );

//output
// array(4) { [0]=> int(7) [1]=> int(0) [2]=> int(0) [3]=> int(0) } 
Sign up to request clarification or add additional context in comments.

Comments

0
<?php
$data_result = explode(",", $rowData[0][13])

for($data_count=0;$data_count<count($data_result);$data_count++)
{
    if(substr($data_result[$data_count], -1) == '-')    
    {
        echo $data_result[$data_count]
    }
}
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.