PHP array example

The other day have some trouble working with an array, gonna leave an example here to have it on hand:

function func(){
$con = pg_connect(“host=127.0.0.1 port=xxxx dbname=xxxxxxxx user=xxxxxxx password=xxxxxxxx”);
$email = pg_query($con,”select xxxxxx from xxxxx ORDER BY xxxx DESC LIMIT 10″);
if (pg_num_rows($email) > 0) {
$row=pg_fetch_all($email);
return $row;
}
}

//func();
$xxx=func();
$var=$xxx[0][“field”];
$var2=$xxx[1][“field”];

All done. Cheers!

Leave a Comment