...

View Full Version : why would you put a "&" infront of a variable



kevinkhan
11-04-2010, 07:44 PM
Does anyone know why there is a "&" infront of the $con variable


$con = null;

function db_connect(&$con, $dbName, $userName, $pwd) {
$con = mysql_connect($localhost, $userName, $pwd);
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbName, $con);
}

MattF
11-04-2010, 07:49 PM
Normally, any alterations made to that var within the function would remain local to the function var. Using the & makes any changes to the var global, so to speak.

kevinkhan
11-04-2010, 07:53 PM
Normally, any alterations made to that var within the function would remain local to the function var. Using the & makes any changes to the var global, so to speak.

thanks now i understand

kevinkhan
11-04-2010, 09:17 PM
and some of this other code. i cant make sense of it


$page = str_ireplace('for (;;);', '', $page);

$json_output = json_decode($page);

$tmp1 = '"pb_'.$profileid.'",';
$tmp2 = ', 100, "Profile");';
$tempstr = substr($json_output->onload[6], strpos($json_output->onload[6],$tmp1)+strlen($tmp1), strpos($json_output->onload[6],$tmp2)-strpos($json_output->onload[6],$tmp1)-strlen($tmp1)) ;

$json_output = json_decode($tempstr);
if($json_output[0]->entities) {
foreach($json_output[0]->entities as $e) {
$linkCnt++;
addToReqTable($curl_handle, $con, $e->href.'&v=info', $cityList, $checkReq, $profileCnt);
$profileCnt++;
}
}

mlseim
11-04-2010, 09:28 PM
I don't want this to come out the wrong way ...
But, it's a good idea to use Google first ... because it's faster to get an answer.

http://www.google.com/search?source=ig&hl=en&rlz=&=&q=json_decode&btnG=Google+Search&aq=f&oq=

MattF
11-04-2010, 09:28 PM
http://uk2.php.net/manual/en/function.json-decode.php

myfayt
11-05-2010, 02:04 AM
Common OOP



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum