0

I am breaking my head on this all day. I am work with a Webservice and once I can get the array back one way or I get it back a different way. So I have a function that strips and pulls the data fro me.

this is the function.

function Detail($a){
            $age= array();
            $countArray = arrayCount($a);

        if ($countArray == 1){


                    array_push ($age,
                        array(
                        "Name"=>$a['Name'],
                         "ProductReference"=>$a['ProductReference'],
                          "AdicRange"=>$a['AdicRange'],
                          "Pages"=>$s['Pages']
                          );        

            }elseif($countArray >= 2){

         foreach ($a as $key => $d) {


            array_push ($age,
                array(
                "Name"=>$d['Name'],
                 "ProductReference"=>$d['ProductReference'],
                  "AdicRange"=>$d['AdicRange'],
                  "Pages"=>$d['Pages']
                 ) );


             }      

            }else{


            }


        return $age;
        }

I am trying t add to the array but I get the array back not correct. This is the array I get back.

Array
(
    [0] => Array
        (


        )

    [1] => Array
        (
            [0] => Array
                (
                    [Name] => 21X29 booklet Ver
                    [ProductReference] => DF0754(A4)
                    [AdicRange] => 4
                    [Pages] => 24
                )

            [1] => Array
                (
                    [Name] => pro book 35X35
                    [ProductReference] => FM8774
                    [AdicRange] => 2
                    [Pages] => 20
                )

            [2] => Array
                (
                    [Name] => pro book 26X10
                    [ProductReference] => FM1032
                    [AdicRange] => 2
                    [Pages] => 20
                )

            [3] => Array
                (
                    [Name] => 21X29 booklet Hor
                    [ProductReference] => DF0750
                    [AdicRange] => 4
                    [Pages] => 24
                )

            [4] => Array
                (
                    [Name] => pro book 35X35
                    [ProductReference] => FM8755
                    [AdicRange] => 2
                    [Pages] => 20
                )

            [5] => Array
                (
                    [Name] => pro book 38X76
                    [ProductReference] => FM0099
                    [AdicRange] => 2
                    [Pages] => 50
                )

            [6] => Array
                (
                    [Name] => pro book 40X80
                    [ProductReference] => FM7291
                    [AdicRange] => 2
                    [Pages] => 20
                )

            [7] => Array
                (
                    [Name] => pro book 30X80
                    [ProductReference] => FM0058
                    [AdicRange] => 2
                    [Pages] => 20
                )

            [8] => Array
                (
                    [Name] => pro book 20X60
                    [ProductReference] => FM1065
                    [AdicRange] => 2
                    [Pages] => 20
                )

        )
)

Can some one please Help me.

I am trying to get the array back like this.

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [Name] => pro book 40X80
                    [ProductReference] => FM7291
                    [AdicRange] => 2
                    [Pages] => 
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [Name] => 21X29 booklet Ver
                    [ProductReference] => DF0754(A4)
                    [AdicRange] => 4
                    [Pages] => 24
                )

            [1] => Array
                (
                    [Name] => pro book 35X35
                    [ProductReference] => FM8774
                    [AdicRange] => 2
                    [Pages] => 20
                )

            [2] => Array
                (
                    [Name] => pro book 26X10
                    [ProductReference] => FM1032
                    [AdicRange] => 2
                    [Pages] => 20
                )

            [3] => Array
                (
                    [Name] => 21X29 booklet Hor
                    [ProductReference] => DF0750
                    [AdicRange] => 4
                    [Pages] => 24
                )

            [4] => Array
                (
                    [Name] => pro book 35X35
                    [ProductReference] => FM8755
                    [AdicRange] => 2
                    [Pages] => 20
                )

            [5] => Array
                (
                    [Name] => pro book 38X76
                    [ProductReference] => FM0099
                    [AdicRange] => 2
                    [Pages] => 50
                )

            [6] => Array
                (
                    [Name] => pro book 40X80
                    [ProductReference] => FM7291
                    [AdicRange] => 2
                    [Pages] => 20
                )

            [7] => Array
                (
                    [Name] => pro book 30X80
                    [ProductReference] => FM0058
                    [AdicRange] => 2
                    [Pages] => 20
                )

            [8] => Array
                (
                    [Name] => pro book 20X60
                    [ProductReference] => FM1065
                    [AdicRange] => 2
                    [Pages] => 20
                )
         [9] => Array
                (
                    [Name] => pro book 40X80
                    [ProductReference] => FM7291
                    [AdicRange] => 2
                    [Pages] => 
                )
        )
)
3
  • your question is not clear. what you want can you give example? Commented Jul 9, 2017 at 16:56
  • What's the logic behind your expected array ? Commented Jul 9, 2017 at 17:06
  • I have to send a array as the example ant the and of the post. Commented Jul 9, 2017 at 17:12

1 Answer 1

0

You were missing a closing parenthesis within your first if clause.

function Detail($a) {
$age = array();
$countArray = arrayCount($a);

if ($countArray == 0) {


    array_push ($age,
    array(
    "Name" => $a['Name'],
    "ProductReference" => $a['ProductReference'],
    "AdicRange" => $a['AdicRange'],
    "Pages" => $s['Pages']
    ));
} elseif ($countArray >= 1) {

    foreach ($a as $key => $d) {


        array_push($age, array(
            "Name" => $d['Name'],
            "ProductReference" => $d['ProductReference'],
            "AdicRange" => $d['AdicRange'],
            "Pages" => $d['Pages']
        ));
    }
} else {

}


return $age;
}
Sign up to request clarification or add additional context in comments.

3 Comments

Same result No change
@DaniEvanRubenstein I updated my answer copy & paste try again. Let me know.
No its not ok. the countArray has to me as i posted it. the webservive that I am using it not so good. have a lock at this post and that is way I am doing it like this. thanks. [link] stackoverflow.com/questions/40457939/…

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.