0

I got this array:

Array
(
    [0] => Array
        (
            [MONTH] => April
            [logs-count] => 14
            [log_type] => 0
        )

    [1] => Array
        (
            [MONTH] => August
            [logs-count] => 942
            [log_type] => 0
        )

    [2] => Array
        (
            [MONTH] => July
            [logs-count] => 132
            [log_type] => 0
        )

    [3] => Array
        (
            [MONTH] => June
            [logs-count] => 114
            [log_type] => 0
        )

    [4] => Array
        (
            [MONTH] => March
            [logs-count] => 424
            [log_type] => 0
        )

    [5] => Array
        (
            [MONTH] => May
            [logs-count] => 79
            [log_type] => 0
        )

    [6] => Array
        (
            [MONTH] => November
            [logs-count] => 269
            [log_type] => 0
        )

    [7] => Array
        (
            [MONTH] => October
            [logs-count] => 4447
            [log_type] => 0
        )

    [8] => Array
        (
            [MONTH] => October
            [logs-count] => 3
            [log_type] => 1
        )


    [9] => Array
        (
            [MONTH] => September
            [logs-count] => 1003
            [log_type] => 0
        )

)

And I want to put this values to 2 arrays where: for each month if log_type = 0, go to 1 array and if log_type = 1, go to 2 array, but if there is log from f (ex November and his log_type is 0 go to 1 array but to second go 0)

So in final it should be like this for example above:

1 array

Array
(
    [0] => 14
    [1] => 942
    [2] => 132
    [3] => 114
    [4] => 424
    [5] => 79
    [6] => 272
    [7] => 4447
    [8] => 1003
)

2 array

Array
(
    [0] => 0
    [1] => 0
    [2] => 0
    [3] => 0
    [4] => 0
    [5] => 0
    [6] => 0
    [7] => 3
    [8] => 0
)
2
  • It's really hard to understand what you want to do. Can you had more details ? Commented Nov 15, 2012 at 14:47
  • I understood the question until: "..but if there is log from f (ex November and his log_type is 0 go to 1 array but to second go 0)" Commented Nov 15, 2012 at 14:48

3 Answers 3

1
$arr0 = [];
$arr1 = [];

foreach ( $arr as $a ) {

    switch ( $a['log_type'] ) {

        case 0:
            $arr0[] = $a['logs-count'];
            break;
        case 1:
            $arr1[] = $a['logs-count'];
            break;
    }

}

This will do the comprehensible part of your question.

Sign up to request clarification or add additional context in comments.

Comments

0

You should use a foreach loop and some conditionnal statements to sort your log entries:

$array1 = array();
$array2 = array();

foreach ($input_array as $entry) {
  if ($entry['MONTH']=='March' && $entry['log_type']==1) {
    $array1[] = $entry['logs-count'];
  } else if // Etc.
}

Adjust the conditional statements according to your taste.

Comments

0

Try:

 $arr = array(array('MONTH' => 'April', 'logs-count' => 14,'log_type' => 0),
 array(...),
 ...
    ); //your array
 $arr1 = $arr2 = array();
 foreach($arr as $v) {
 if( $v['log_type'] === 0 ) {
   $arr1[] = $v['logs-count'];
   $arr2[] = 0;
 }
 else if($v['log_type'] === 1) 
   $arr2[] =  $v['logs-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.