Add array to array without keys [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I know this must be a huge newbie question, but I didn't find the correct answer. Let's see. I have an array set:
$global_array = array();
Then, I want to add an arry inside $global_array, but I dont want the keys. So, the result I want to get is:
$global_array = array(
array(
'bla',
'bla'
)
);
Sorry for the noob question. Thanks!

This should help:
$global_array[] = array('bla','bla');
All arrays will have keys...
If not defined as default 0,1,2,3...

Related

How to insert php post name into a variable? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a post value named $_POST['John'] and I want to insert the post name "John" into a variable but not its value. How can I achieve this? Code Sample:
$_POST['John'] = "value";
array_keys is PHP function which is returning the keys from an array, you have only single array than we can use 0 as the key. if you have more than one array element you can use loop.
You can use array_keys as you mentioned there is one parameter use
$a = array_keys($_POST)[0];
https://3v4l.org/NUkkL

Shorten useless coding? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Creating my loading screen on garrys mod, and seeing this "useless" coding, and was betting that there is a way to shorten it massively, however I am quite a php nooby and was wondering if there was a perhaps a way to use arrays or something to make it easier/shorter? Code Here
$array = array(
"gm_flatgrass" => "Flatgrass",
"cs_assault" => "CS Assault",
"de_train" => "",
...
);
$getmap = $_GET['mapname'];
if(array_key_exists($getmap,$array)) {
$map = $array[$getmap];
}

How to insert POST data [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I do not know how to insert POST data to mongodb collection. I try to do it like this:
$collection ->insert($_POST);
But in this case I get An Internal Server Error. What is the best and most concise way to do it?
Better way to make an array of all post data and pass it to insert like
<?php
$post = array("username" =>$_POST['username'], "password" => $_POST['password']);
$collection->insert($post);
?>

Recreating a dynamic php array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a php array which is created from data in an sql database.
All I want to do is recreate that identical array on another site.
I can print_r it no worries. But how would I output the structure of the array so that I can go as follows on the new site.
$newvar = array(.....);
I'm sure it's a very simply question, But I can't find an answer.
serialize Try this function. I think this is what you need
you can use json_encode to send your array and keep the structure of your array.

How to make array construction? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i have a problem. I have two arrays and i need to put one into other like this:
array('1'=>1,'2'=>2,'3'=>array());
Can somebody advise how to solve it?
If your first array is
$first = array('1'=>1,'2'=>2)
And the second is
$second = array()
Then just add it in as
$first[] = $second
If the second is
$second[3] = array();
Then you want array_merge
$first = array_merge($first,$second)
There are all sorts of array functions on the left in that link, which come in very handy.

Categories