I found a function to check requirements from a tutorial of script. i want to convert it into an array , can anyone please please convert it into array ? i will highly appriciate it.. function is : function check_requirements() { $requirements = array (); #PHP Vesion $result = array ('req' =>('PHP Version >= 4.1')); $result['ok'] = @ version_compare (@ phpversion(), '4.1', '>='); $result['txt'] = '('.@ phpversion().')'; if (!$result['ok']) $result['txt'] .= ('script may not work. Please upgrade!'); $requirements[] = $result; #Server API $result = array ('req' => ('Server API')); $result['ok'] = php_sapi_name() != "cgi"; if ($result['ok']) $result['txt'] = '('.php_sapi_name().')'; else $result['txt'] = ('CGI mode is likely to have problems.'); $requirements[] = $result; #GD support $result = array ('req' => ('GD Support (for visual confirmations)')); $result['ok'] = extension_loaded ('gd'); if ($result['ok']) { ob_start(); @ phpinfo(8); $module_info = @ ob_get_contents(); @ ob_end_clean(); if (preg_match ("/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i", $module_info, $matches)) $result['txt'] = '('.$matches[1].')'; unset ($module_info, $matches); } else $result['txt'] = ('Visual confirmation functionality will not be available.'); $requirements[] = $result; #Session Save Path writable? $result = array ('req' => ('Session Save Path writable?')); $sspath = @ ini_get ('session.save_path'); if (preg_match ("`.+;(.*)`", $sspath, $matches)) { $sspath = $matches[1]; unset ($matches); } if (!$sspath) { $result['ok'] = false; $result['txt'] = ('Warning: <span class="item">session.save_path ('.$sspath.')</span> is not set.'); } elseif (is_dir ($sspath) && is_writable ($sspath)) { $result['ok'] = true; $result['txt'] = '<span class="item">('.$sspath.')</span>'; } else { $result['ok'] = false; $result['txt'] = ('Warning: <span class="item">##sspath##</span> not existing or not writable.'); $result['txt'] = str_replace ('##sspath##', $sspath, $r['txt']); } $requirements[] = $result; #MySQL Support $result = array ('req' => ('MySQL Support')); $result['ok'] = function_exists ('mysql_connect'); if (!$result['ok']) { $result['txt'] = ('Not available.'); $result['fatal'] = true; } else { $mysql_version = @ mysql_get_server_info(); if (empty ($mysql_version)) { @ ob_start(); @ phpinfo(8); $module_info = @ ob_get_contents(); @ ob_end_clean(); if (preg_match ("/\bClient\s+API\s+version\b[^\d\n\r]+?([\d\.]+)/i", $module_info, $matches)) $mysql_version = $matches[1]; } $result['txt'] = '('.(!empty ($mysql_version) ? trim ($mysql_version) : ('Unknown MySQL server version')).')'; } $requirements[] = $result; #./include/config.php writable? $result = array ('req' => ('./include/config.php writable?')); $fn = INSTALL_PATH.'include/config.php'; if (!is_writable ($fn)) @ chmod ($fn, 0777); $result['ok'] = is_writable ($fn); if (!$result['ok']) { $result['txt'] = ('Fatal: '.INSTALL_PATH.'include/config.php is not writable, installation cannot continue.'); $result['fatal'] = true; } $requirements[] = $result; #./temp writable? $result = array ('req' => ('./temp writable?')); $fn = INSTALL_PATH.'/temp'; if (!is_writable ($fn)) @chmod($fn, 0777); $result['ok'] = is_writable ($fn); if (!$result['ok']) { $result['txt'] = ('Fatal: '.INSTALL_PATH.'temp is not writable, installation cannot continue.'); $result['fatal'] = true; } $requirements[] = $result; #./temp/templates writable? $result = array ('req' => ('./temp/templates writable?')); $fn = INSTALL_PATH.'temp/templates'; if (!is_writable ($fn)) @ chmod ($fn, 0777); $result['ok'] = is_writable ($fn); if (!$result['ok']) { $result['txt'] = ('Fatal: '.INSTALL_PATH.'temp/templates is not writable, installation cannot continue.'); $result['fatal'] = true; } $requirements[] = $result; return $requirements; } PHP: any help would be great thanks..
$requirements[] = $result; return $requirements; } PHP: This function is already returning an array. Try following $my_arr = check_requirements(); print_r($my_arr);// print array returned from function PHP: It should display all array elements if function is working without errors.
I think this is what you want... The following works because the function returns an array $array = check_requirements(); print_r($array); function check_requirements() { $requirements = array (); #PHP Vesion $result = array ('req' =>('PHP Version >= 4.1')); $result['ok'] = @ version_compare (@ phpversion(), '4.1', '>='); $result['txt'] = '('.@ phpversion().')'; if (!$result['ok']) $result['txt'] .= ('script may not work. Please upgrade!'); $requirements[] = $result; #Server API $result = array ('req' => ('Server API')); $result['ok'] = php_sapi_name() != "cgi"; if ($result['ok']) $result['txt'] = '('.php_sapi_name().')'; else $result['txt'] = ('CGI mode is likely to have problems.'); $requirements[] = $result; #GD support $result = array ('req' => ('GD Support (for visual confirmations)')); $result['ok'] = extension_loaded ('gd'); if ($result['ok']) { ob_start(); @ phpinfo(8); $module_info = @ ob_get_contents(); @ ob_end_clean(); if (preg_match ("/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i", $module_info, $matches)) $result['txt'] = '('.$matches[1].')'; unset ($module_info, $matches); } else $result['txt'] = ('Visual confirmation functionality will not be available.'); $requirements[] = $result; #Session Save Path writable? $result = array ('req' => ('Session Save Path writable?')); $sspath = @ ini_get ('session.save_path'); if (preg_match ("`.+;(.*)`", $sspath, $matches)) { $sspath = $matches[1]; unset ($matches); } if (!$sspath) { $result['ok'] = false; $result['txt'] = ('Warning: <span class="item">session.save_path ('.$sspath.')</span> is not set.'); } elseif (is_dir ($sspath) && is_writable ($sspath)) { $result['ok'] = true; $result['txt'] = '<span class="item">('.$sspath.')</span>'; } else { $result['ok'] = false; $result['txt'] = ('Warning: <span class="item">##sspath##</span> not existing or not writable.'); $result['txt'] = str_replace ('##sspath##', $sspath, $r['txt']); } $requirements[] = $result; #MySQL Support $result = array ('req' => ('MySQL Support')); $result['ok'] = function_exists ('mysql_connect'); if (!$result['ok']) { $result['txt'] = ('Not available.'); $result['fatal'] = true; } else { $mysql_version = @ mysql_get_server_info(); if (empty ($mysql_version)) { @ ob_start(); @ phpinfo(8); $module_info = @ ob_get_contents(); @ ob_end_clean(); if (preg_match ("/\bClient\s+API\s+version\b[^\d\n\r]+?([\d\.]+)/i", $module_info, $matches)) $mysql_version = $matches[1]; } $result['txt'] = '('.(!empty ($mysql_version) ? trim ($mysql_version) : ('Unknown MySQL server version')).')'; } $requirements[] = $result; #./include/config.php writable? $result = array ('req' => ('./include/config.php writable?')); $fn = INSTALL_PATH.'include/config.php'; if (!is_writable ($fn)) @ chmod ($fn, 0777); $result['ok'] = is_writable ($fn); if (!$result['ok']) { $result['txt'] = ('Fatal: '.INSTALL_PATH.'include/config.php is not writable, installation cannot continue.'); $result['fatal'] = true; } $requirements[] = $result; #./temp writable? $result = array ('req' => ('./temp writable?')); $fn = INSTALL_PATH.'/temp'; if (!is_writable ($fn)) @chmod($fn, 0777); $result['ok'] = is_writable ($fn); if (!$result['ok']) { $result['txt'] = ('Fatal: '.INSTALL_PATH.'temp is not writable, installation cannot continue.'); $result['fatal'] = true; } $requirements[] = $result; #./temp/templates writable? $result = array ('req' => ('./temp/templates writable?')); $fn = INSTALL_PATH.'temp/templates'; if (!is_writable ($fn)) @ chmod ($fn, 0777); $result['ok'] = is_writable ($fn); if (!$result['ok']) { $result['txt'] = ('Fatal: '.INSTALL_PATH.'temp/templates is not writable, installation cannot continue.'); $result['fatal'] = true; } $requirements[] = $result; return $requirements; } PHP:
You don't 'call' arrays, you call functions, which then return a result (this may be an array). I'm not sure if you should be messing around with PHP if you don't know the difference between these two concepts, but to print the contents of an array you can use: var_dump($array); PHP:
Don't learn php the hard way, go get a book, you will learn more reading the book than hacking around in 1 year