Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add to array values

Tags:

arrays

sql

php

I geting from mysql data:

$starcik_o = mysql_query("select id, mapa, miasto, nazwa_obiektu from oferty where id = 28");
        while($data = mysql_fetch_array($starcik_o, MYSQL_ASSOC)) $punkty[] = $data;

And I want to add another table in to this array, I trying to do it like that:

foreach ($punkty as $item)
        {
        $deserialized = unserialize($item['mapa']);
        $punkty['long'] = $deserialized['lng'];
        $punkty['lat'] = $deserialized['lat'];
        }

But it's not working like I want to, becouse var_dump($punkty); showing me

array(3) 
{ 
    [0]=> array(4) 
    { 
    ["id"]=> string(2) "28" 
    ["mapa"]=> string(97) "a:3:{s:3:"lat";s:17:"49.21103723075132";s:3:"lng";s:18:"22.330280542373657";s:4:"zoom";s:2:"17";}" 
    ["miasto"]=> string(5) "Cisna" 
    ["nazwa_obiektu"]=> string(44) "Cisna - noclegi u Mirosławy w Bieszczadach" 
    } 
    ["long"]=> string(18) "22.330280542373657" 
    ["lat"]=> string(17) "49.21103723075132" 
}
like image 401
ariel Avatar asked Nov 29 '25 04:11

ariel


1 Answers

    foreach ($punkty as &$item)
    {
        $deserialized = unserialize($item['mapa']);
        $item['long'] = $deserialized['lng'];
        $item['lat'] = $deserialized['lat'];
    }
like image 158
Ozerich Avatar answered Nov 30 '25 17:11

Ozerich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!