Friday, 19 September 2014

PHP: Add an item to your current array

//Current data

Array
    (
        [0] => Array
            (
                [uuid] => 365
                [name] => August_Kidsmeals.mp4
                [title] => 
                [path] => file://C:/wamp/www/chopperv2/video/library/
                [duration] => 00:30:00
                [uploaded_date] => 2014-07-22
                [uploaded_by] => admin
                [keyword] => 
                [comment] => 
            )

        [1] => Array
            (
                [uuid] => 368
                [name] => August_breakfast.mp4
                [title] => 
                [path] => file://C:/wamp/www/chopperv2/video/library/
                [duration] => 00:30:00
                [uploaded_date] => 2014-07-22
                [uploaded_by] => admin
                [keyword] => 
                [comment] => 
            )
    )

//required data
 [0] => Array
        (
            [uuid] => 365
            [name] => August_Kidsmeals.mp4
            [title] => 
            [path] => file://C:/wamp/www/chopperv2/video/library/
            [duration] => 00:30:00
            [uploaded_date] => 2014-07-22
            [uploaded_by] => admin
            [keyword] => 
            [comment] => 
            [select] => 1      //  <<------    I WANT THIS
        )


Answer:
<?php
// no need to unsetting numeric indexed values, all are in associative now
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC); 
foreach($rows as &$row) { 
 $row['selected'] = true;
 }
?>

0 comments:

Post a Comment