本文整理汇总了PHP中array_push函数的典型用法代码示例。如果您正苦于以下问题:PHP array_push函数的具体用法?PHP array_push怎么用?PHP array_push使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_push函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: inet6_expand
/**
* Expand an IPv6 Address
*
* This will take an IPv6 address written in short form and expand it to include all zeros.
*
* @param string $addr A valid IPv6 address
* @return string The expanded notation IPv6 address
*/
function inet6_expand($addr)
{
/* Check if there are segments missing, insert if necessary */
if (strpos($addr, '::') !== false) {
$part = explode('::', $addr);
$part[0] = explode(':', $part[0]);
$part[1] = explode(':', $part[1]);
$missing = array();
for ($i = 0; $i < 8 - (count($part[0]) + count($part[1])); $i++) {
array_push($missing, '0000');
}
$missing = array_merge($part[0], $missing);
$part = array_merge($missing, $part[1]);
} else {
$part = explode(":", $addr);
}
// if .. else
/* Pad each segment until it has 4 digits */
foreach ($part as &$p) {
while (strlen($p) < 4) {
$p = '0' . $p;
}
}
// foreach
unset($p);
/* Join segments */
$result = implode(':', $part);
/* Quick check to make sure the length is as expected */
if (strlen($result) == 39) {
return $result;
} else {
return false;
}
// if .. else
}
示例2: smarty_function_link_list
function smarty_function_link_list($params, &$smarty1)
{
global $smarty;
global $db;
global $cfg;
$tbl_link = $cfg['tbl_link'];
if (empty($params['template'])) {
$template = "link_list.html";
}
if (empty($params['count'])) {
$count = 5;
}
if (empty($params['catalog_id'])) {
print "function article_detail required catalog_id";
return;
}
extract($params);
if ($smarty->is_cached($template, $catalog_id)) {
$smarty->display($template, $catalog_id);
return;
}
$sql = "select name , url , descri ,logo ,sort_order from {$tbl_link} where catalog = {$catalog_id} order by sort_order desc limit {$count}";
$rs = $db->Execute($sql);
$links = array();
while ($arr = $rs->FetchRow()) {
array_push($links, $arr);
}
$rs->close();
$smarty->assign("links", $links);
$smarty->display($template, $catalog_id);
}
示例3: query_operon_gene_percentage
function query_operon_gene_percentage($species_id)
{
$spe = array();
$spe['name'] = '';
$spe['ncs'] = array();
$spe['total_gene'] = 0;
$spe['in_operon'] = 0;
$species_id = mysql_real_escape_string($species_id);
$sql = "SELECT id, name FROM Species WHERE id={$species_id}";
$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
$row = mysql_fetch_array($result);
$spe['name'] = $row['name'];
unset($result);
$sql = "SELECT id,NC_id,protein_gene_number,rna_gene_number,operon_number FROM NC WHERE species_id={$species_id}";
$result = mysql_query($sql) or die("Invalid query: " . mysql_error());
$n = mysql_num_rows($result);
for ($i = 0; $i < $n; $i++) {
$row = mysql_fetch_array($result);
$NC_id = $row['id'];
$row['total_gene_num'] = $row['protein_gene_number'] + $row['rna_gene_number'];
$sql2 = "SELECT sum(size) as total_genes FROM Operon WHERE size>=2 AND NC_id={$NC_id} ORDER BY id";
$result2 = mysql_query($sql2) or die("Invalid query: " . mysql_error());
$row2 = mysql_fetch_array($result2);
$row['gene_in_operon'] = $row2['total_genes'];
#$row['percent'] = round($row['gene_in_operon'] / $row['total_gene_num'],2);
array_push($spe['ncs'], $row);
$spe['total_gene'] += $row['total_gene_num'];
$spe['in_operon'] += $row['gene_in_operon'];
}
$spe['percent'] = round(100 * $spe['in_operon'] / $spe['total_gene'], 2);
return $spe;
}
示例4: process_start
function process_start($process_name)
{
$this =& progress::instance();
$this->current_process = $process_name;
array_push($this->processes_stack, $process_name);
$this->write('started', PROCESS_STARTED);
}
示例5: getLocation
function getLocation($str)
{
$array_size = intval(substr($str, 0, 1));
// 拆成的行数
$code = substr($str, 1);
// 加密后的串
$len = strlen($code);
$subline_size = $len % $array_size;
// 满字符的行数
$result = array();
$deurl = "";
for ($i = 0; $i < $array_size; $i += 1) {
if ($i < $subline_size) {
array_push($result, substr($code, 0, ceil($len / $array_size)));
$code = substr($code, ceil($len / $array_size));
} else {
array_push($result, substr($code, 0, ceil($len / $array_size) - 1));
$code = substr($code, ceil($len / $array_size) - 1);
}
}
for ($i = 0; $i < ceil($len / $array_size); $i += 1) {
for ($j = 0; $j < count($result); $j += 1) {
$deurl = $deurl . "" . substr($result[$j], $i, 1);
}
}
return str_replace("^", "0", urldecode($deurl));
}
示例6: read
private function read($arg)
{
$sql = 'SELECT ';
$fields = array();
if ($arg == null) {
$this->fields = array_values($this->modelInfo['fields']);
foreach ($this->modelInfo['fields'] as $k => $v) {
array_push($fields, $k . ' as ' . $v);
}
} else {
$args = explode(',', $arg);
$this->fields = $args;
foreach ($args as $v) {
array_push($fields, array_search($v, $this->modelInfo['fields']) . ' as ' . $v);
}
}
$sql .= join(',', $fields);
$sql .= ' FROM ' . join(',', $this->modelInfo['tables']);
$sql .= ' WHERE ' . join(' and ', $this->modelInfo['links']);
if ($this->where) {
$sql .= ' and ' . $this->where;
}
if ($this->order) {
$sql .= ' ORDER BY ' . $this->order;
}
if ($this->limit) {
$sql .= ' LIMIT ' . $this->limit;
}
DEVE and debug::$sql[] = $sql;
$mysqli = $this->mysqli->prepare($sql) or debug::error('没有查询到数据!', 113004);
$mysqli->execute();
$mysqli->store_result();
return $mysqli;
}
示例7: testPush
/**
* @depends testEmpty
*/
public function testPush(array $arr)
{
array_push($arr, 'foo');
$this->assertEquals('foo', $arr[count($arr) - 1]);
$this->assertFalse(empty($arr));
return $arr;
}
示例8: _struct_to_array
/**
* _struct_to_array($values, &$i)
*
* This is adds the contents of the return xml into the array for easier processing.
* Recursive, Static
*
* @access private
* @param array $values this is the xml data in an array
* @param int $i this is the current location in the array
* @return Array
*/
function _struct_to_array($values, &$i)
{
$child = array();
if (isset($values[$i]['value'])) {
array_push($child, $values[$i]['value']);
}
while ($i++ < count($values)) {
switch ($values[$i]['type']) {
case 'cdata':
array_push($child, $values[$i]['value']);
break;
case 'complete':
$name = $values[$i]['tag'];
if (!empty($name)) {
$child[$name] = is_null($values[$i]['value']) ? '' : $values[$i]['value'];
//$child[$name]= ($values[$i]['value'])?($values[$i]['value']):'';
if (isset($values[$i]['attributes'])) {
$child[$name] = $values[$i]['attributes'];
}
}
break;
case 'open':
$name = $values[$i]['tag'];
$size = isset($child[$name]) ? sizeof($child[$name]) : 0;
$child[$name][$size] = $this->_struct_to_array($values, $i);
break;
case 'close':
return $child;
break;
}
}
return $child;
}
示例9: findDirs
/**
* Returns an array of found directories
*
* This function checks every found directory if they match either $uid or $gid, if they do
* the found directory is valid. It uses recursive function calls to find subdirectories. Due
* to the recursive behauviour this function may consume much memory.
*
* @param string path The path to start searching in
* @param integer uid The uid which must match the found directories
* @param integer gid The gid which must match the found direcotries
* @param array _fileList recursive transport array !for internal use only!
* @return array Array of found valid pathes
*
* @author Martin Burchert <martin.burchert@syscp.de>
* @author Manuel Bernhardt <manuel.bernhardt@syscp.de>
*/
function findDirs($path, $uid, $gid)
{
$list = array($path);
$_fileList = array();
while (sizeof($list) > 0) {
$path = array_pop($list);
$path = makeCorrectDir($path);
$dh = opendir($path);
if ($dh === false) {
standard_error('cannotreaddir', $path);
return null;
} else {
while (false !== ($file = @readdir($dh))) {
if ($file == '.' && (fileowner($path . '/' . $file) == $uid || filegroup($path . '/' . $file) == $gid)) {
$_fileList[] = makeCorrectDir($path);
}
if (is_dir($path . '/' . $file) && $file != '..' && $file != '.') {
array_push($list, $path . '/' . $file);
}
}
@closedir($dh);
}
}
return $_fileList;
}
示例10: generateField
/**
* Create new form item for depending on specified file type.
*
* File extension determine on specified value of `$file_type`.
* For twig-files generate:
* form.field(model, 'attribute').name(value, options)
* Value and options are automatically converted into a Json-like string.
* For php-files generate:
* form->field($model, 'attribute')->name(value, options)
* Value and options are automatically converted into an array-like string.
*
* @param string $attribute form item attribute
* @param array $value form item default value|values of attribute
* @param int $file_tpe extension of the current file
* @param null|string $name form item input type (if any)
* @param array $options form item additional options
* @return string new form item for specified file extension
*/
public static function generateField($attribute, $value = [], $file_tpe = Generator::TEMPLATE_TYPE_PHP, $name = null, $options = [])
{
switch ($file_tpe) {
case Generator::TEMPLATE_TYPE_TWIG:
$delimiter = '.';
$field_string = "form{$delimiter}field(model, '{$attribute}')";
//$options_container = '{' . preg_replace('|\=>|', ':', $options) . '}';
$string_formatter = new Json();
$method = 'encode';
break;
default:
$delimiter = '->';
$field_string = "\$form{$delimiter}field(\$model, '{$attribute}')";
//$options_container = "[{$options}]";
$string_formatter = new VarDumper();
$method = 'export';
}
if ($name) {
$field_string = $field_string . $delimiter . "{$name}";
$options_container = [];
if ($value) {
array_push($options_container, $string_formatter::$method($value));
}
if ($options) {
array_push($options_container, $string_formatter::$method($options));
}
if ($options_container) {
$options_container = preg_replace('|"|', "'", implode(', ', $options_container));
$field_string = "{$field_string}({$options_container})";
} else {
$field_string = "{$field_string}()";
}
}
return $field_string;
}
示例11: parseRequest
/**
* Parse the incoming request in a RESTful way
*
* @param \PASL\Web\Service\Request The request object
*/
public function parseRequest($oRequest)
{
$oRequestData = array();
switch ($_SERVER['REQUEST_METHOD']) {
case 'GET':
$oRequestHash = $_REQUEST;
break;
case 'POST':
$oRequestHash = $_REQUEST;
break;
case 'PUT':
parse_str(file_get_contents("php://input"), $oRequestHash);
break;
}
foreach ($oRequestHash as $val) {
if (trim($val) != "" && !is_null($val)) {
array_push($oRequest->oRequestHash, $val);
}
}
$oRequest->requestPayload = $oRequestData;
$oRequest->method = $oRequest->oRequestHash[2];
// Grab the method arguments
$methodArgs = $oRequest->oRequestHash;
array_shift($methodArgs);
array_shift($methodArgs);
array_shift($methodArgs);
$oRequest->methodArgs = $methodArgs;
return $oRequest;
}
示例12: toObject
/**
* Convert SimpleXML object to stdClass object.
*
* @return object
*/
public function toObject()
{
$attributes = $this->attributes();
$children = $this->children();
$textValue = trim((string) $this);
if (count($attributes) === 0 and count($children) === 0) {
return $textValue;
} else {
$object = new \StdClass();
foreach ($attributes as $key => $value) {
$object->{$key} = (string) $value;
}
if (!empty($textValue)) {
$object->_ = $textValue;
}
foreach ($children as $value) {
$name = $value->getName();
if (isset($object->{$name})) {
if (is_array($object->{$name})) {
array_push($object->{$name}, $value->toObject());
} else {
$object->{$name} = [$object->{$name}, $value->toObject()];
}
} else {
$object->{$name} = $value->toObject();
}
}
return $object;
}
}
示例13: execute
function execute($requests)
{
if (!OPENPNE_USE_ALBUM) {
handle_kengen_error();
}
$v = array();
$target_c_album_image_ids = $requests['target_c_album_image_ids'];
// アルバム写真が選択されていない場合はエラー
if (!$target_c_album_image_ids) {
admin_client_redirect('edit_album_image_list', "アルバム写真が選択されていません");
}
$id_ary = split(":", $target_c_album_image_ids);
$album_image_list = array();
foreach ($id_ary as $id) {
$album_image = db_album_image_get_c_album_image4id($id);
if (!$album_image) {
admin_client_redirect('edit_album_image_list', '指定されたアルバムは存在しません');
}
$member = db_member_c_member4c_member_id($album_image['c_member_id']);
$album_image['c_member'] = $member;
array_push($album_image_list, $album_image);
}
$this->set('album_image_list', $album_image_list);
$this->set('target_c_album_image_ids', $target_c_album_image_ids);
$this->set($v);
return 'success';
}
示例14: retrieveDatasFromDB
public function retrieveDatasFromDB($videoId)
{
$query = "SELECT Records.userid, value, second FROM Records WHERE Records.videoid=" . $videoId . ' ORDER BY userid, second;';
$result = $this->conn->query($query);
$valueArray = array("user" => array());
$userValues = array("id" => 0, "values" => array());
$i = 0;
if ($result->num_rows > 0) {
//$allRows = $result -> fetch_all(MYSQLI_ASSOC);
//print_r(var_dump($allRows));
while ($row = $result->fetch_assoc()) {
if ($i != 0) {
if (strcmp($previousUser, $row["userid"])) {
array_push($valueArray["user"], $userValues);
$userValues = array("id" => 0, "values" => array());
}
}
$previousUser = $row["userid"];
$i++;
$userValues["id"] = $previousUser;
array_push($userValues["values"], $row["value"]);
}
array_push($valueArray["user"], $userValues);
} else {
echo "O rows";
}
//print_r(var_dump($valueArray));
$this->conn->close();
return $valueArray;
}
示例15: process
public function process($args)
{
$this->output = "";
if (strlen(trim($args)) > 0) {
try {
$url = "https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&maxResults=3&type=video&q=" . urlencode($args) . "&key=" . $this->apikey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$respuesta = curl_exec($ch);
curl_close($ch);
$resultados = json_decode($respuesta);
if (isset($resultados->error)) {
$this->output = "Ocurrió un problema al realizar la busqueda: " . $resultados->error->errors[0]->reason;
} else {
if (count($resultados->items) > 0) {
$videos = array();
foreach ($resultados->items as $video) {
array_push($videos, "http://www.youtube.com/watch?v=" . $video->id->videoId . " - " . $video->snippet->title);
}
$this->output = join("\n", $videos);
} else {
$this->output = "No se pudieron obtener resultados al realizar la busqueda indicada.";
}
}
} catch (Exception $e) {
$this->output = "Ocurrió un problema al realizar la busqueda: " . $e->getMessage();
}
} else {
$this->output = "Digame que buscar que no soy adivino.";
}
}