Jump to content

can I add many var in on var? like array?


samoi

Recommended Posts

hello guys

 

how are you?

 

can I merge many vars in only one var?

 

an example:

 

<?php
$conn = mysql_connect("localhost", "root", "root");
$db = mysql_select_db("data_base");

$username = $_POST['username'];
$password = $_POST['password'];

$whatever = "whatever var";

$also_a_var = "whatever added vars";

?>

 

Can any one explain how can I put all of them in only one var? and explain if there are exceptions for any functions like (isset) or any other functions.

 

 

Thank you all!

Link to comment
Share on other sites

I'm sorry, I think I didn't delievered the question very well.

 

ok I have this code: [which is for registration and so.]

 

<?php
$conn = mysql_connect("localhost", "root", "pass");
$db = mysql_select_db("d_base");

$username = $_POST['username'];
$pass = $_POST['password'];

if(some expression){
// do this
}
else{
// do this
}

echo $something_from_the_if_statement ;
?>

 

I'm sorry but I'm a beginner to the PHP. and I'm wondering if I can let this whole code execute by scripting only one var?

 

 

:( I'm sorry I really don't know how to explain and that's due my English is not my mother lang, and still a beginner to the PHP.

 

Thank you guys

Link to comment
Share on other sites

to be more clear

 

as of the example in my second reply, can I do like this?

 


$merge = array_this(conn, db, username, pass);

 

is this right? or no?

 

Guys, I'm just asking and wondering if that's possible!

 

I know I can just include this code or require it. but I'm wondering if I can collect all of these vars and put them all in only one var and let it execute itself

Link to comment
Share on other sites

Erm, so you want to merge them all together, then no that wouldn't be usable then. So as i said, just keep it simple for now until you have a better understanding.

 

:)

 

thank you man, but as I said I need an explanation why I can't do it?

is it because I can't array a function? what do you think?

Link to comment
Share on other sites

you can do it like this:

$the_array = array();

$the_array[] = "localhost";
$the_array[] = "bla bla";
$the_array[] = $something;

like that, but doing it in this order is usually for a set of information that has no need for signatures or labels. you cant use this like this:

$the_array[] = "localhost";
$the_array[] = "root";
$the_array[] = "root";

$conn = mysql_connect($the_array)

you should be doing this instead:

$the_array['a'] = "localhost";
$the_array['b'] = "root";
$the_array['c'] = "root";

$conn = mysql_connect($the_array['a'],$the_array['b'],$the_array['c'])

Link to comment
Share on other sites

I don't think this works

$the_array[] = "localhost";
$the_array[] = "root";
$the_array[] = "root";

$conn = mysql_connect($the_array)

Because it will do

$conn = mysql_connect(array(3)) // or something like this.

 

yup, that's what i said... you cant use it like that... i haven't tried it, but i just know it wouldn't work  ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.