How to push array in PHP [closed]












0















I want to put data from Query into array, but this code is not working. can you explain the right way ? thanks



$sql = "SELECT * FROM populasi WHERE blablabla";
$result = $con->query($sql);
$tampung = array();
foreach ($result as $m) {
$tampung = array_push($tampung, "new google.maps.LatLng($m[x], $m[y]), ");
}
echo $tampung;









share|improve this question













closed as off-topic by Alon Eitan, RiggsFolly, Michael Dodd, jww, Pearly Spencer Nov 14 '18 at 16:53


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Alon Eitan, RiggsFolly, Michael Dodd, jww, Pearly Spencer

If this question can be reworded to fit the rules in the help center, please edit the question.

















  • Read about explode() (Although it looks wrong overall I must say)

    – Alon Eitan
    Nov 14 '18 at 10:26








  • 3





    array_push() returns an integer so by doing $tampung = array_push( ... ) you're reassigning $tampung to an (int) ... ditch the $tampung = bit.

    – CD001
    Nov 14 '18 at 10:28








  • 1





    OR a simple $tampung = "new google.maps.LatLng($m[x], $m[y]), "

    – RiggsFolly
    Nov 14 '18 at 10:29






  • 1





    As manual suggests it is quicker if you are only adding one item to the array to use $x = $y; syntax over array_push() as you then dont need to call a function

    – RiggsFolly
    Nov 14 '18 at 10:31













  • Best way to push some element into your array is $tampung = "new google.maps.LatLng($m[x], $m[y]),". This method is faster then using array_push(). To print array, please use print_r() or var_dump(). If you want to print pretty formated array and you didn't installed XDebug use echo <pre>; print_r($yourArrayHere);. This small construction will prettify array output and will help you to read it.

    – alexey-novikov
    Nov 14 '18 at 10:39
















0















I want to put data from Query into array, but this code is not working. can you explain the right way ? thanks



$sql = "SELECT * FROM populasi WHERE blablabla";
$result = $con->query($sql);
$tampung = array();
foreach ($result as $m) {
$tampung = array_push($tampung, "new google.maps.LatLng($m[x], $m[y]), ");
}
echo $tampung;









share|improve this question













closed as off-topic by Alon Eitan, RiggsFolly, Michael Dodd, jww, Pearly Spencer Nov 14 '18 at 16:53


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Alon Eitan, RiggsFolly, Michael Dodd, jww, Pearly Spencer

If this question can be reworded to fit the rules in the help center, please edit the question.

















  • Read about explode() (Although it looks wrong overall I must say)

    – Alon Eitan
    Nov 14 '18 at 10:26








  • 3





    array_push() returns an integer so by doing $tampung = array_push( ... ) you're reassigning $tampung to an (int) ... ditch the $tampung = bit.

    – CD001
    Nov 14 '18 at 10:28








  • 1





    OR a simple $tampung = "new google.maps.LatLng($m[x], $m[y]), "

    – RiggsFolly
    Nov 14 '18 at 10:29






  • 1





    As manual suggests it is quicker if you are only adding one item to the array to use $x = $y; syntax over array_push() as you then dont need to call a function

    – RiggsFolly
    Nov 14 '18 at 10:31













  • Best way to push some element into your array is $tampung = "new google.maps.LatLng($m[x], $m[y]),". This method is faster then using array_push(). To print array, please use print_r() or var_dump(). If you want to print pretty formated array and you didn't installed XDebug use echo <pre>; print_r($yourArrayHere);. This small construction will prettify array output and will help you to read it.

    – alexey-novikov
    Nov 14 '18 at 10:39














0












0








0








I want to put data from Query into array, but this code is not working. can you explain the right way ? thanks



$sql = "SELECT * FROM populasi WHERE blablabla";
$result = $con->query($sql);
$tampung = array();
foreach ($result as $m) {
$tampung = array_push($tampung, "new google.maps.LatLng($m[x], $m[y]), ");
}
echo $tampung;









share|improve this question














I want to put data from Query into array, but this code is not working. can you explain the right way ? thanks



$sql = "SELECT * FROM populasi WHERE blablabla";
$result = $con->query($sql);
$tampung = array();
foreach ($result as $m) {
$tampung = array_push($tampung, "new google.maps.LatLng($m[x], $m[y]), ");
}
echo $tampung;






php arrays






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 10:24









Ehsar D. M.Ehsar D. M.

61




61




closed as off-topic by Alon Eitan, RiggsFolly, Michael Dodd, jww, Pearly Spencer Nov 14 '18 at 16:53


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Alon Eitan, RiggsFolly, Michael Dodd, jww, Pearly Spencer

If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by Alon Eitan, RiggsFolly, Michael Dodd, jww, Pearly Spencer Nov 14 '18 at 16:53


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Alon Eitan, RiggsFolly, Michael Dodd, jww, Pearly Spencer

If this question can be reworded to fit the rules in the help center, please edit the question.













  • Read about explode() (Although it looks wrong overall I must say)

    – Alon Eitan
    Nov 14 '18 at 10:26








  • 3





    array_push() returns an integer so by doing $tampung = array_push( ... ) you're reassigning $tampung to an (int) ... ditch the $tampung = bit.

    – CD001
    Nov 14 '18 at 10:28








  • 1





    OR a simple $tampung = "new google.maps.LatLng($m[x], $m[y]), "

    – RiggsFolly
    Nov 14 '18 at 10:29






  • 1





    As manual suggests it is quicker if you are only adding one item to the array to use $x = $y; syntax over array_push() as you then dont need to call a function

    – RiggsFolly
    Nov 14 '18 at 10:31













  • Best way to push some element into your array is $tampung = "new google.maps.LatLng($m[x], $m[y]),". This method is faster then using array_push(). To print array, please use print_r() or var_dump(). If you want to print pretty formated array and you didn't installed XDebug use echo <pre>; print_r($yourArrayHere);. This small construction will prettify array output and will help you to read it.

    – alexey-novikov
    Nov 14 '18 at 10:39



















  • Read about explode() (Although it looks wrong overall I must say)

    – Alon Eitan
    Nov 14 '18 at 10:26








  • 3





    array_push() returns an integer so by doing $tampung = array_push( ... ) you're reassigning $tampung to an (int) ... ditch the $tampung = bit.

    – CD001
    Nov 14 '18 at 10:28








  • 1





    OR a simple $tampung = "new google.maps.LatLng($m[x], $m[y]), "

    – RiggsFolly
    Nov 14 '18 at 10:29






  • 1





    As manual suggests it is quicker if you are only adding one item to the array to use $x = $y; syntax over array_push() as you then dont need to call a function

    – RiggsFolly
    Nov 14 '18 at 10:31













  • Best way to push some element into your array is $tampung = "new google.maps.LatLng($m[x], $m[y]),". This method is faster then using array_push(). To print array, please use print_r() or var_dump(). If you want to print pretty formated array and you didn't installed XDebug use echo <pre>; print_r($yourArrayHere);. This small construction will prettify array output and will help you to read it.

    – alexey-novikov
    Nov 14 '18 at 10:39

















Read about explode() (Although it looks wrong overall I must say)

– Alon Eitan
Nov 14 '18 at 10:26







Read about explode() (Although it looks wrong overall I must say)

– Alon Eitan
Nov 14 '18 at 10:26






3




3





array_push() returns an integer so by doing $tampung = array_push( ... ) you're reassigning $tampung to an (int) ... ditch the $tampung = bit.

– CD001
Nov 14 '18 at 10:28







array_push() returns an integer so by doing $tampung = array_push( ... ) you're reassigning $tampung to an (int) ... ditch the $tampung = bit.

– CD001
Nov 14 '18 at 10:28






1




1





OR a simple $tampung = "new google.maps.LatLng($m[x], $m[y]), "

– RiggsFolly
Nov 14 '18 at 10:29





OR a simple $tampung = "new google.maps.LatLng($m[x], $m[y]), "

– RiggsFolly
Nov 14 '18 at 10:29




1




1





As manual suggests it is quicker if you are only adding one item to the array to use $x = $y; syntax over array_push() as you then dont need to call a function

– RiggsFolly
Nov 14 '18 at 10:31







As manual suggests it is quicker if you are only adding one item to the array to use $x = $y; syntax over array_push() as you then dont need to call a function

– RiggsFolly
Nov 14 '18 at 10:31















Best way to push some element into your array is $tampung = "new google.maps.LatLng($m[x], $m[y]),". This method is faster then using array_push(). To print array, please use print_r() or var_dump(). If you want to print pretty formated array and you didn't installed XDebug use echo <pre>; print_r($yourArrayHere);. This small construction will prettify array output and will help you to read it.

– alexey-novikov
Nov 14 '18 at 10:39





Best way to push some element into your array is $tampung = "new google.maps.LatLng($m[x], $m[y]),". This method is faster then using array_push(). To print array, please use print_r() or var_dump(). If you want to print pretty formated array and you didn't installed XDebug use echo <pre>; print_r($yourArrayHere);. This small construction will prettify array output and will help you to read it.

– alexey-novikov
Nov 14 '18 at 10:39












2 Answers
2






active

oldest

votes


















0














you can do it like this



foreach ($result as $m) {
$tampung = 'new google.maps.LatLng('.$m[x].', '.$m[y].')';
}
var_dump($tampung);


You can not echo array, use var_dump($arr) or print_r($arr) instead






share|improve this answer
























  • We dont normally answer TYPO's we just make a simple comment and close the question as a typo.

    – RiggsFolly
    Nov 14 '18 at 10:32



















0














You are just executing the query, you have not fetched it.
Fetch it to an array first :



$data=$result->fetch_assoc();


than you can use array_push function






share|improve this answer


























  • Assuming this is mysqli - the question never specifies what $con is so it could be a custom database wrapper where the query() method returns an iterable recordset ... unlikely but it could be.

    – CD001
    Nov 14 '18 at 10:34













  • To make a complete answer you really should also mention the other error i.e. the incorrect use of array_push()

    – RiggsFolly
    Nov 14 '18 at 10:35




















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














you can do it like this



foreach ($result as $m) {
$tampung = 'new google.maps.LatLng('.$m[x].', '.$m[y].')';
}
var_dump($tampung);


You can not echo array, use var_dump($arr) or print_r($arr) instead






share|improve this answer
























  • We dont normally answer TYPO's we just make a simple comment and close the question as a typo.

    – RiggsFolly
    Nov 14 '18 at 10:32
















0














you can do it like this



foreach ($result as $m) {
$tampung = 'new google.maps.LatLng('.$m[x].', '.$m[y].')';
}
var_dump($tampung);


You can not echo array, use var_dump($arr) or print_r($arr) instead






share|improve this answer
























  • We dont normally answer TYPO's we just make a simple comment and close the question as a typo.

    – RiggsFolly
    Nov 14 '18 at 10:32














0












0








0







you can do it like this



foreach ($result as $m) {
$tampung = 'new google.maps.LatLng('.$m[x].', '.$m[y].')';
}
var_dump($tampung);


You can not echo array, use var_dump($arr) or print_r($arr) instead






share|improve this answer













you can do it like this



foreach ($result as $m) {
$tampung = 'new google.maps.LatLng('.$m[x].', '.$m[y].')';
}
var_dump($tampung);


You can not echo array, use var_dump($arr) or print_r($arr) instead







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 10:31









Oleksandr PobutaOleksandr Pobuta

32429




32429













  • We dont normally answer TYPO's we just make a simple comment and close the question as a typo.

    – RiggsFolly
    Nov 14 '18 at 10:32



















  • We dont normally answer TYPO's we just make a simple comment and close the question as a typo.

    – RiggsFolly
    Nov 14 '18 at 10:32

















We dont normally answer TYPO's we just make a simple comment and close the question as a typo.

– RiggsFolly
Nov 14 '18 at 10:32





We dont normally answer TYPO's we just make a simple comment and close the question as a typo.

– RiggsFolly
Nov 14 '18 at 10:32













0














You are just executing the query, you have not fetched it.
Fetch it to an array first :



$data=$result->fetch_assoc();


than you can use array_push function






share|improve this answer


























  • Assuming this is mysqli - the question never specifies what $con is so it could be a custom database wrapper where the query() method returns an iterable recordset ... unlikely but it could be.

    – CD001
    Nov 14 '18 at 10:34













  • To make a complete answer you really should also mention the other error i.e. the incorrect use of array_push()

    – RiggsFolly
    Nov 14 '18 at 10:35


















0














You are just executing the query, you have not fetched it.
Fetch it to an array first :



$data=$result->fetch_assoc();


than you can use array_push function






share|improve this answer


























  • Assuming this is mysqli - the question never specifies what $con is so it could be a custom database wrapper where the query() method returns an iterable recordset ... unlikely but it could be.

    – CD001
    Nov 14 '18 at 10:34













  • To make a complete answer you really should also mention the other error i.e. the incorrect use of array_push()

    – RiggsFolly
    Nov 14 '18 at 10:35
















0












0








0







You are just executing the query, you have not fetched it.
Fetch it to an array first :



$data=$result->fetch_assoc();


than you can use array_push function






share|improve this answer















You are just executing the query, you have not fetched it.
Fetch it to an array first :



$data=$result->fetch_assoc();


than you can use array_push function







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 10:33









RiggsFolly

70.7k1864111




70.7k1864111










answered Nov 14 '18 at 10:32









xhuljoxhuljo

524




524













  • Assuming this is mysqli - the question never specifies what $con is so it could be a custom database wrapper where the query() method returns an iterable recordset ... unlikely but it could be.

    – CD001
    Nov 14 '18 at 10:34













  • To make a complete answer you really should also mention the other error i.e. the incorrect use of array_push()

    – RiggsFolly
    Nov 14 '18 at 10:35





















  • Assuming this is mysqli - the question never specifies what $con is so it could be a custom database wrapper where the query() method returns an iterable recordset ... unlikely but it could be.

    – CD001
    Nov 14 '18 at 10:34













  • To make a complete answer you really should also mention the other error i.e. the incorrect use of array_push()

    – RiggsFolly
    Nov 14 '18 at 10:35



















Assuming this is mysqli - the question never specifies what $con is so it could be a custom database wrapper where the query() method returns an iterable recordset ... unlikely but it could be.

– CD001
Nov 14 '18 at 10:34







Assuming this is mysqli - the question never specifies what $con is so it could be a custom database wrapper where the query() method returns an iterable recordset ... unlikely but it could be.

– CD001
Nov 14 '18 at 10:34















To make a complete answer you really should also mention the other error i.e. the incorrect use of array_push()

– RiggsFolly
Nov 14 '18 at 10:35







To make a complete answer you really should also mention the other error i.e. the incorrect use of array_push()

– RiggsFolly
Nov 14 '18 at 10:35





Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."