views:

30

answers:

1

I have this array,

Array
(
    [campaign_title] => adasdasdasddsad
    [campaign_keyword] => asdsadasdasdasdasd
    [introduction] => asdasdasdasdasdasdsa
    [campaign_headline] => Array
        (
            [0] => asdasdasdasdasdasdad
        )

    [article] => Array
        (
            [0] => asdasdasdasdasdasdasdasdsadas
        )
    [save_multiple] => Save
)

Basically I need away to send the the campaign_headline and article array to a DB so that each headline and article are saved to the same row, then the next headline and article are saved to the same row etc

+1  A: 
foreach ($x['campaign_headline'] as $key => $headline)
{
    store_into_db($headline, $x['article'][$key]);
}

function store_into_db($headline, $article)
{
    /* there you must store article into DB, i can write this code but i must more infomraiton about, db server type and tables password etc. */
}
Svisstack
for beter optimisation put `sizeof($x['campaign_headline'])` outside the loop
Dobiatowski
for better reading, use `foreach($campaign['campaign_headline] as $i => $headline)`
salathe
@Dobiatowski: This is not a optimisation because sizeof working in O(1) not in O(n) time, then this is doesn't meater
Svisstack
@Svisstack: It does matter, because calling a function is far more expensive than accessing the value of a variable. But foreach is even faster ;)
nikic