本文整理汇总了PHP中push函数的典型用法代码示例。如果您正苦于以下问题:PHP push函数的具体用法?PHP push怎么用?PHP push使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了push函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateAndSave
/**
* Validate inputs and save to database.
*
* @return Response
*/
protected function validateAndSave($post)
{
$validator = Validator::make(Input::all(), Post::$rules);
if ($validator->fails()) {
Session::flash('errorMessage', 'Validation failed');
return Redirect::back()->withInput()->withErrors($validator);
} else {
$post->title = Input::get('title');
$post->content = Input::get('content');
$post->user_id = Auth::id();
$image = Input::file('image');
if ($image) {
$filename = $image->getClientOriginalName();
$post->image = '/uploaded/' . $filename;
$image->move('uploaded/', $filename);
}
$result = $post->save();
$posttags = Input::has('tuttags') ? Input::get('tuttags') : array();
if (Input::has('addtags')) {
$addtag = Input::get('addtags');
$posttags . push($addtag);
}
$post->tags()->sync($posttags);
$post->save();
if ($result) {
Session::flash('successMessage', 'Great Success!');
return Redirect::action('PostsController@show', $post->slug);
} else {
Session::flash('errorMessage', 'Post was not saved.');
return Redirect::back()->withInput();
}
}
}
示例2: __invoke
public function __invoke()
{
$today = $this->getDateInThePast(0);
$oneWeekAgo = $this->getDateInThePast(7);
$twoWeeksAgo = $this->getDateInThePast(14);
$threeWeeksAgo = $this->getDateInThePast(21);
$service = $this->adwords->getService('AdGroupService');
$selector = new \Selector();
$selector->predicates = [new \Predicate('Status', 'EQUALS', 'ENABLED'), new \Predicate('CampaignStatus', 'EQUALS', 'ENABLED')];
$selector->orderBy = new \OrderBy('ctr', 'ASCENDING');
$selector->paging = new \Paging(0, \AdWordsConstants::RECOMMENDED_PAGE_SIZE);
do {
$page = $service->get($selector);
if (is_array($page->entries)) {
foreach ($page->entries as $adGroup) {
// Let's look at the trend of the ad group's CTR.
$statsThreeWeeksAgo = $this->getStatsFor($adGroup, $threeWeeksAgo, $twoWeeksAgo);
$statsTwoWeeksAgo = $this->getStatsFor($adGroup, $twoWeeksAgo, $oneWeekAgo);
$statsLastWeek = $this->getStatsFor($adGroup, $oneWeekAgo, $today);
// Week over week, the ad group is declining - record that!
if ($statsLastWeek->getCtr() < $statsTwoWeeksAgo->getCtr() && $statsTwoWeeksAgo->getCtr() < $statsThreeWeeksAgo->getCtr()) {
reportRows . push([adGroup . getCampaign() . getName(), adGroup . getName(), statsLastWeek . getCtr() * 100, statsLastWeek . getCost(), statsTwoWeeksAgo . getCtr() * 100, statsTwoWeeksAgo . getCost(), statsThreeWeeksAgo . getCtr() * 100, statsThreeWeeksAgo . getCost()]);
}
}
}
$selector->paging->startIndex += $selector->paging->numberResults;
} while (!is_null($page->entries));
}
示例3: addSnippet
public function addSnippet(Tx_T3tt_Domain_Model_XsltSnippet $snippetFile)
{
if (strlen($snippetFile->getContent()) > 0) {
$this->_snippets . push($snippetFile);
} else {
throw new Tx_T3tt_Domain_Model_Exception_InvalidParamsException("Snippet `" . $snippetFile . "' is empty.");
}
}
示例4: addProductToList
public function addProductToList($productReference, $active)
{
//var result = file_put_contents($this->productListFile, $productReference, FILE_APPEND | LOCK_EX);
if ($active === TRUE) {
$this->activeProducts . push($productReference);
} else {
$this->notActiveProducts . push($productReference);
}
}
示例5: response_to_POST
function response_to_POST()
{
if ($_POST) {
// if data was sent
push($GLOBALS['db'], $_POST);
$_SESSION['db'] = $GLOBALS['db'];
// save to session (to be avaliable on the next request)
}
echo '{"comments": ' . json_encode($GLOBALS['db']) . '}';
}
示例6: addKey
private function addKey($key)
{
push($this->keys, $key);
$connection = ssh2_connect($this->server->ip);
$rC = 0;
do {
//ssh2_exec($connection, "echo #$key->contact@$this->server >> $this->home/.ssh/authorized_keys");
//ssh2_exec($connection, "echo $key->pubKey >> $this->home/.ssh/authorized_keys");
sleep(1);
$rC++;
} while (!$stream && $rC < 3);
}
示例7: signForRequestToken
/**
* Sign the request when requesting a request token
* @param $curl
* @param $urlCallback
* @param $signatureMethod
*/
public function signForRequestToken($curl, $urlCallback, $signatureMethod = null)
{
if( $signatureMethod === null)
{
$signatureMethod = new \Zeflasher\OAuth\SignatureMethods\OAuthSignatureMethodHmacSha1();
}
$oauthParameters = new \Zeflasher\OAuth\Client\OAuthParameters($this->_consumerKey, $signatureMethod);
$oauthParameters->addParameters(urlRequest.data);
$oauthParameters->addParameters(_getGETParameters(urlRequest));
$oauthParameters->add(OAuthConstants.CALLBACK, urlCallback);
$signature = getSignature(urlRequest, oauthParameters, OAuthConstants.EMPTY_TOKEN_SECRET, signatureMethod);
$oauthParameters->add(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE, $signature);
//
$headerString = $oauthParameters->getAuthorizationHeaderValue();
urlRequest.requestHeaders.push(\Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_HEADER, $headerString);
}
示例8: getUsers
private function getUsers($connection)
{
/* get users with dir in /home/. try three times (with 1sec pause) --> planned to make an extra method somewhere else for this */
$rC = 0;
do {
$stream = ssh2_exec($connection, 'cat /etc/passwd | grep "/home" |cut -d: -f1,6');
sleep(1);
$rC++;
} while (!$stream && $rC < 3);
/* split the output by newline */
$usersHomes = preg_split('/$\\R?^/m', stream_get_contents($stream));
/* make a new user for every line and add it to the $users-array */
foreach ($usersHomes as $uH) {
$userAttrs = array(explode(':', $uH));
push($this->users, new User($userAttrs[0], $userAttrs[1], $this->name));
}
/* if adminUser is root add it to the array too ('cause he'd not be catched by the "grep /home" below */
if ($this->adminUser->name == "root") {
push($this->users, new User("root", "/root/", $this->name));
}
}
示例9: inp
function inp($columnid, $arrayOFchisla, $n)
{
$massiv = array();
$res;
$IDc;
$massiv . push(columnid);
$res = 1;
$IDc = columnid - 1;
while (IDc != 0) {
$massiv . push(IDc);
$res = res + 1;
$IDc--;
}
$IDc = columnid + 1;
while (IDc != 0) {
$massiv . push(IDc);
$res = res + 1;
$IDc++;
}
$a = array();
$a[1] = ia($massiv, $res, $arrayOFchisla, $inparr);
$a[0] = $res;
return $a;
}
示例10: switch
switch ($action) {
case 'pulldef':
$content = \SimpleSAML\Utils\HTTP::fetch($base . 'export.php?aid=' . $application . '&type=def&file=' . $basefile);
file_put_contents($fileWithoutExt . '.definition.json', $content);
break;
case 'pull':
try {
$content = \SimpleSAML\Utils\HTTP::fetch($base . 'export.php?aid=' . $application . '&type=translation&file=' . $basefile);
file_put_contents($fileWithoutExt . '.translation.json', $content);
} catch (SimpleSAML_Error_Exception $e) {
echo 'Translation unavailable for ' . $basefile;
SimpleSAML_Logger::warning("Translation unavailable for {$basefile} in {$base}: " . $e->getMessage());
}
break;
case 'push':
push($file, $basefile, $application, $type);
break;
case 'convert':
include $file;
$definition = json_format(convert_definition($lang));
$translation = json_format(convert_translation($lang)) . "\n";
file_put_contents($fileWithoutExt . '.definition.json', $definition);
file_put_contents($fileWithoutExt . '.translation.json', $translation);
break;
default:
throw new Exception('Unknown action [' . $action . ']');
}
function ssp_readline($prompt = '')
{
echo $prompt;
return rtrim(fgets(STDIN), "\n");
示例11: push
function push($m)
{
$a = func_get_args();
$f = $a[0];
if (!isIn($f, array('replace', 'byIndex', 'auto', 'distinct', 'begin'))) {
$f = 'auto';
} else {
mov_next($a);
}
while (list($i, $v) = each($a)) {
push($this->O, $f, $v);
}
return $this;
}
示例12: __invoke
public function __invoke()
{
$this->createLabel();
$alert_text = [];
$history = [];
$currentTime = new \DateTime();
$today = $currentTime->format('m') + 1 + "/" + $currentTime . getDate() + "/" + $currentTime->format('Y');
$keywordIterator;
$line_counter = 0;
while ($keywordIterator->hasNext()) {
$keyword = keywordIterator . next();
$line_counter++;
$current_quality_score = $keyword->qualityScore;
$keywordLabelsIterator = keyword . labels() . withCondition("Name STARTS_WITH 'QS: '") . get();
if ($keywordLabelsIterator->hasNext()) {
$keyword_label = $keywordLabelsIterator . next();
$matches = new RegExp('QS: ([0-9]+)$') . exec($keyword_label . getName());
$old_quality_score = $matches[1];
} else {
$old_quality_score = 0;
}
// For the history also note the change or whether this keyword is new
if ($old_quality_score > 0) {
$change = $current_quality_score - $old_quality_score;
} else {
$change = "NEW";
}
$row = [$today, $keyword . getCampaign() . getName(), $keyword . getAdGroup() . getName(), $keyword . getText(), $current_quality_score, $change];
$history . push(row);
// If there is a previously tracked quality score and it's different from the current one...
if ($old_quality_score > 0 && $current_quality_score != $old_quality_score) {
// Make a note of this to log it and possibly send it via email later
$alert_text . push($current_quality_score + "\t" + $old_quality_score + "\t" + $change + "\t" + $keyword . getText());
// Remove the old label
$keyword . removeLabel($keyword_label . getName());
}
// Store the current QS for the next time by using a label
$keyword . applyLabel("QS: " + $current_quality_score);
}
if ($line_counter == 0) {
$this->logger->log("Couldn't find any keywords marked for quality score tracking. To mark keywords for tracking, apply the label '" + $label_name + "' to those keywords.");
return;
}
$this->logger->log("Tracked " + $line_counter + " keyword quality scores. To select different keywords for tracking, apply the label '" + $label_name + "' to those keywords.");
// Store history
$history_sheet = spreadsheet . getSheetByName('QS history');
$history_sheet . getRange($history_sheet . getLastRow() + 1, 1, $history . length, 6) . setValues($history);
// If there are notes for alerts then prepare a message to log and possibly send via email
if ($alert_text . length) {
$message = "The following quality score changes were discovered:\nNew\tOld\tChange\tKeyword\n";
for ($i = 0; $i < count($alert_text); $i++) {
$message += $alert_text[i] + "\n";
}
// Also include a link to the spreadsheet
$message += "\n" + "The complete history is available at " + $spreadsheet . getUrl();
$this->logger->log($message);
// If there is an email address send out a notification
if ($email_address && $email_address != "YOUR_EMAIL_HERE") {
$this->mailer->sendEmail($email_address, "Quality Score Tracker: Changes detected", $message);
}
}
}
示例13: die
default:
die('Error: Invalid cause!');
}
$time = time();
$response = 0;
$message = htmlentities($_POST['text']);
$db = new PDO($dbpdodsn, $dbuser, $dbpassword, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$st_addcall = $db->prepare('INSERT INTO calls (callid, deviceid, type, time, response, message, reminded) VALUES (:cid, :did, :ty, :ti, :re, :m, 0)');
$st_addcall->bindParam(':cid', $callid);
$st_addcall->bindParam(':did', $deviceid);
$st_addcall->bindParam(':ty', $type);
$st_addcall->bindParam(':ti', $time);
$st_addcall->bindParam(':re', $response);
$st_addcall->bindParam(':m', $message);
$st_addcall->execute();
push($deviceid, $callid, $type, $time, $message, false);
header('Location: wait.php?callid=' . $callid);
die('Redirecting...');
}
pageheader(0, "Choosing cause");
?>
<p>Enter the cause by pressing the corresponding button. If you want to add text (optional), enter your message before pressing the button.</p>
<form method="post">
<button class="submitbutton" type="submit" name="cause" value="1">Food</button>
<button class="submitbutton" type="submit" name="cause" value="2">IT help</button>
<!-- TODO: Better translation. -->
<button class="submitbutton" type="submit" name="cause" value="3">Contact gewenst</button>
<p class="title">Extra tekst (Optioneel)</p>
<input type="text" name="text">
</form>
<?php
示例14: getParts
public function getParts($vehicleID = 0, $mount = "", $year = "", $make = "", $model = "", $style = "")
{
$req = "";
if ($vehicleID > 0) {
$req = $this->config->getDomain() . "GetParts";
$req .= "&dataType=" . $this->config->getDataType();
} else {
}
$resp = $this->helper->curlGet($req);
$part_arr = array();
foreach (json_decode($resp) as $part) {
$part_arr . push($part);
}
return $part_arr;
}
示例15: parser_performAction
function parser_performAction(&$thisS, $yytext, $yyleng, $yylineno, $yystate, $S, $_S, $O)
{
switch ($yystate) {
case 1:
return $S[$O - 1];
break;
case 2:
return [['']];
break;
case 3:
$thisS = [$S[$O]];
break;
case 4:
$thisS = [];
break;
case 5:
$thisS = [''];
break;
case 6:
$thisS = $S[$O - 1];
break;
case 7:
$S[$O - 1][$S[$O - 1] . length - 1] . push('');
$thisS = $S[$O - 1];
break;
case 8:
$S[$O - 2] . push($S[$O]);
$thisS = $S[$O - 2];
break;
case 9:
$S[$O - 2][$S[$O - 2] . length - 1] . push('');
$S[$O - 2] . push($S[$O]);
$thisS = $S[$O - 2];
break;
case 10:
$thisS = [$S[$O]];
break;
case 11:
$thisS = $S[$O - 1];
break;
case 12:
$thisS = [''];
break;
case 13:
//$thisS = [];
break;
case 14:
$S[$O - 1] . push('');
$thisS = $S[$O - 1];
break;
case 15:
//$S[$O-1].push('');
$thisS = $S[$O - 1];
break;
case 16:
$S[$O - 2] . push('');
$S[$O - 2] . push($S[$O]);
$thisS = $S[$O - 2];
break;
case 17:
//$S[$O-2].push('');
$S[$O - 2] . push($S[$O]);
$thisS = $S[$O - 2];
break;
case 18:
$thisS = '';
break;
case 19:
$thisS = $S[$O - 1];
break;
case 15:
$thisS = $S[$O];
break;
case 20:
$thisS = $S[$O - 1] + '' + $S[$O];
break;
}
}