Link to home
Start Free TrialLog in
Avatar of erzoolander
erzoolander

asked on

Build SQL Query from multiple arrays / PHP

I've got an array that looks like this..

Array
(
    [fm] => Array
        (
            [133.74] => Array
                (
                    [base] => Array
                        (
                            [0] => 2015-09-29
                            [1] => 2015-09-30
                        )

                )

            [202.59] => Array
                (
                    [base] => Array
                        (
                            [0] => 2015-10-01
                        )

                )

        )

    [fmtax] => Array
        (
            [13.51] => Array
                (
                    [0] => 2015-09-29
                    [1] => 2015-09-30
                )

            [20.46] => Array
                (
                    [0] => 2015-10-01
                )

        )

)

Open in new window


and I need to build a SQL statement to insert the relevant values.  I'm thinking it will need to be a unique query for each array  item.

So I'll end up needing something like

$sql = "insert into mytable ('price', 'tax', 'date') values ('133.74', '13.51', '2015-09-29')";

What I've got so far is this...

foreach ($sale['fm'] as $key => $value) {
	$i=0;
	$g=count($value['base']);
	while($i < $g) {
		echo($sale['fm'][$key]['base'][$i]."<br />");
		$i++;
	}
}

Open in new window


which does well for the "fm" key - but I'm getting hung up on how to grab the value from the second associated "fmtax" array key.  I was thinking using something like current/next as it iterates through...but am kinda scratching my head on it.

Any help would be appreciated :)
SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial