当前位置: 首页>>代码示例>>PHP>>正文


PHP SplFixedArray::key方法代码示例

本文整理汇总了PHP中SplFixedArray::key方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFixedArray::key方法的具体用法?PHP SplFixedArray::key怎么用?PHP SplFixedArray::key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SplFixedArray的用法示例。


在下文中一共展示了SplFixedArray::key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getFavoriteByTweetId

 /**
  * gets the Favorite by tweet it id
  *
  * @param \PDO $pdo PDO connection object
  * @param int $tweetId tweet id to search for
  * @return \SplFixedArray array of Favorites found or null if not found
  * @throws \PDOException when mySQL related errors occur
  * @throws \TypeError when variables are not the correct data type
  **/
 public static function getFavoriteByTweetId(\PDO $pdo, int $tweetId)
 {
     // sanitize the tweet id
     $tweetId = filter_var($tweetId, FILTER_VALIDATE_INT);
     if ($tweetId <= 0) {
         throw new \PDOException("tweet id is not positive");
     }
     // create query template
     $query = "SELECT profileId, tweetId, favoriteDate FROM favorite WHERE tweetId = :tweetId";
     $statement = $pdo->prepare($query);
     // bind the member variables to the place holders in the template
     $parameters = ["tweetId" => $tweetId];
     $statement->execute($parameters);
     // build an array of favorites
     $favorites = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $favorite = new Favorite($row["tweetId"], $row["profileId"], $row["favoriteDate"]);
             $favorites[$favorites->key()] = $favorite;
             $favorites->next();
         } catch (\Exception $exception) {
             // if the row couldn't be converted, rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $favorites;
 }
开发者ID:jfindley2,项目名称:data-design,代码行数:37,代码来源:Favorite.php

示例2: storeSQLResultsInArray

 /**
  * function to store multiple database results into an SplFixedArray
  *
  * @param PDOStatement $statement pdo statement object
  * @return SPLFixedArray all message obtained from database
  * @throws PDOException if mySQL related errors occur
  */
 public static function storeSQLResultsInArray(PDOStatement $statement)
 {
     //build an array of messages, as an SPLFixedArray object
     //set the size of the object to the number of retrieved rows
     $retrievedMessages = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     //while rows can still be retrieved from the result
     while (($row = $statement->fetch()) !== false) {
         try {
             $message = new Message($row["messageId"], $row["listingId"], $row["orgId"], $row["messageText"]);
             //place result in the current field, then advance the key
             $retrievedMessages[$retrievedMessages->key()] = $message;
             $retrievedMessages->next();
         } catch (Exception $exception) {
             //rethrow the exception if retrieval failed
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $retrievedMessages;
 }
开发者ID:brbrown59,项目名称:bread-basket,代码行数:27,代码来源:message.php

示例3: SplFixedArray

<?php

$array = new SplFixedArray(3);
$array[0] = "Hello";
$array[1] = "world";
$array[2] = "elePHPant";
foreach ($array as $value) {
    echo $array->key(array("this", "should", "not", "execute"));
}
开发者ID:badlamer,项目名称:hhvm,代码行数:9,代码来源:SplFixedArray_key_param.php

示例4: getAllImages

 /**
  * getAllImages
  *
  * @param \PDO $pdo PDO connection object
  * @return \SplFixedArray SplFixedArray of images found or null if not found
  * @throws \PDOException when mySQL related errors occur
  * @throws \TypeError when variables are not the correct data type
  **/
 public static function getAllImages(\PDO $pdo)
 {
     // create query template
     $query = "SELECT imageId, imageProfileId, imageFileName, imageType FROM image";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // build an array of images
     $images = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $image = new Image($row["imageId"], $row["imageProfileId"], $row["imageFileName"], $row["imageType"]);
             $images[$images->key()] = $image;
             $images->next();
         } catch (\Exception $exception) {
             // if the row couldn't be converted, rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $images;
 }
开发者ID:ng-abq,项目名称:ng-abq,代码行数:29,代码来源:Image.php

示例5: getAllRatings

 /**
  * gets all ratings
  *
  * @param PDO $pdo PDO connection object
  * @return SplFixedArray all ratings found
  * @throws PDOException when mySQL errors occur
  */
 public static function getAllRatings(PDO $pdo)
 {
     //create query template
     $query = "select trailId, userId, rating FROM rating";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // build an array of rating values
     $ratings = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $rating = new Rating($row["userId"], $row["trailId"], $row["ratingValue"]);
             $ratings[$ratings->key()] = $rating;
             $ratings->next();
         } catch (Exception $exception) {
             // if the row couldn't be converted rethrow it
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $ratings;
 }
开发者ID:jmsaul,项目名称:open-trails,代码行数:28,代码来源:rating.php

示例6: key

 public function key()
 {
     echo "A::key\n";
     return parent::key();
 }
开发者ID:badlamer,项目名称:hhvm,代码行数:5,代码来源:fixedarray_003.php

示例7: getSegmentBySegmentStopElevation

 /**
  * gets segment by segmentStopElevation
  *
  * @param PDO $pdo pointer to PDO connection
  * @param int $segmentStopElevation stop elevation to trail-search for
  * @return mixed segment found or null if not found
  * @throws PDOException when mySQL related errors occur
  * @throws RangeException when range is invalid
  * @throws Exception for other exception
  */
 public static function getSegmentBySegmentStopElevation(PDO &$pdo, $segmentStopElevation)
 {
     //sanitize the int before searching
     try {
         $segmentStopElevation = Filter::filterInt($segmentStopElevation, "segment stop", false);
     } catch (InvalidArgumentException $invalidArgument) {
         throw new PDOException($invalidArgument->getMessage(), 0, $invalidArgument);
     } catch (RangeException $range) {
         throw new RangeException($range->getMessage(), 0, $range);
     } catch (Exception $exception) {
         throw new Exception($exception->getMessage(), 0, $exception);
     }
     //create query template
     $query = "SELECT segmentId, ST_AsWKT(segmentStop) AS segmentStop, ST_AsWKT(segmentStart) AS segmentStart, segmentStartElevation, segmentStopElevation FROM segment WHERE segmentStopElevation = :segmentStopElevation";
     $statement = $pdo->prepare($query);
     //binds segmentStopElevation to placeholder
     $parameters = array("segmentStopElevation" => $segmentStopElevation);
     $statement->execute($parameters);
     //build an array of segments
     $segments = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $segmentStartJSON = Gisconverter::wktToGeojson($row["segmentStart"]);
             $segmentStopJSON = Gisconverter::wktToGeojson($row["segmentStop"]);
             $segmentStartGenericObject = json_decode($segmentStartJSON);
             $segmentStopGenericObject = json_decode($segmentStopJSON);
             $segmentStart = new Point($segmentStartGenericObject->coordinates[0], $segmentStartGenericObject->coordinates[1]);
             $segmentStop = new Point($segmentStopGenericObject->coordinates[0], $segmentStopGenericObject->coordinates[1]);
             $segment = new Segment($row["segmentId"], $segmentStart, $segmentStop, $row["segmentStartElevation"], $row["segmentStopElevation"]);
             $segments[$segments->key()] = $segment;
             $segments->next();
         } catch (Exception $e) {
             //if the row couldn't be converter, rethrow it
             throw new PDOException($e->getMessage(), 0, $e);
         }
     }
     return $segments;
 }
开发者ID:jmsaul,项目名称:open-trails,代码行数:49,代码来源:segment.php

示例8: getAllTweets

 /**
  * gets all Tweets
  *
  * @param PDO $pdo pointer to PDO connection, by reference
  * @return mixed SplFixedArray of Tweets found or null if not found
  * @throws PDOException when mySQL related errors occur
  **/
 public static function getAllTweets(PDO &$pdo)
 {
     // create query template
     $query = "SELECT tweetId, profileId, tweetContent, tweetDate FROM tweet";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // build an array of tweets
     $tweets = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $tweet = new Tweet($row["tweetId"], $row["profileId"], $row["tweetContent"], $row["tweetDate"]);
             $tweets[$tweets->key()] = $tweet;
             $tweets->next();
         } catch (Exception $exception) {
             // if the row couldn't be converted, rethrow it
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     // count the results in the array and return:
     // 1) null if 0 results
     // 2) the entire array if >= 1 result
     $numberOfTweets = count($tweets);
     if ($numberOfTweets === 0) {
         return null;
     } else {
         return $tweets;
     }
 }
开发者ID:ericdebelak,项目名称:angular-mvc,代码行数:36,代码来源:tweet.php

示例9: getAllListingTypes

 /**
  * retrieves all listingtypes
  *
  * @param PDO $pdo pdo connection object
  * @return SplFixedArray all organizations
  * @throws PDOException if mySQL errors occur
  */
 public static function getAllListingTypes(PDO $pdo)
 {
     //create query template and execute
     $query = "SELECT listingTypeId, listingType FROM listingType";
     $statement = $pdo->prepare($query);
     $statement->execute();
     //build an array of the retrieved results
     //set the size of the object to the number of retrieved rows
     $retrievedTypes = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     //while rows can still be retrieved from the result
     while (($row = $statement->fetch()) !== false) {
         try {
             $listingType = new ListingType($row["listingTypeId"], $row["listingType"]);
             //place result in the current field, then advance the key
             $retrievedTypes[$retrievedTypes->key()] = $listingType;
             $retrievedTypes->next();
         } catch (Exception $exception) {
             //rethrow the exception if retrieval failed
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $retrievedTypes;
 }
开发者ID:brbrown59,项目名称:bread-basket,代码行数:31,代码来源:listingtype.php

示例10: getAllProductLocations

 /**
  * gets all ProductLocations
  *
  * @param PDO $pdo pointer to PDO connection, by reference
  * @return SplFixedArray all productLocations found
  * @throws PDOException when mySQL related errors occur
  **/
 public static function getAllProductLocations(PDO &$pdo)
 {
     // create query template
     $query = "SELECT locationId, productId, unitId, quantity FROM productLocation";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // build an array of ProductLocation(s)
     $productLocations = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $productLocation = new ProductLocation($row["locationId"], $row["productId"], $row["unitId"], $row["quantity"]);
             $productLocations[$productLocations->key()] = $productLocation;
             $productLocations->next();
         } catch (PDOException $exception) {
             // if the row couldn't be converted, rethrow it
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $productLocations;
 }
开发者ID:sandidgec,项目名称:foodinventory,代码行数:28,代码来源:product-location.php

示例11: getAllGame

 /**
  * gets all Game
  *
  * @param \PDO $pdo PDO connection object
  * @return \SplFixedArray SplFixedArray of Game found or null if not found
  * @throws \PDOException when mySQL related errors occur
  * @throws \TypeError when variables are not the correct data type
  **/
 public static function getAllGame(\PDO $pdo)
 {
     //create query template
     $query = "SELECT gameId, gameFirstTeamId, gameSecondTeamId, gameTime FROM game ";
     $statement = $pdo->prepare($query);
     $statement->execute();
     //build an array of game
     $games = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $game = new Game($row["gameId"], $row["gameFirstTeamId"], $row["gameSecondTeamId"], $row["gameTime"]);
             $games[$games->key()] = $game;
             $games->next();
         } catch (\Exception $exception) {
             // if the row couldn't be converted rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $games;
 }
开发者ID:chrispaul3625,项目名称:sprots,代码行数:29,代码来源:Game.php

示例12: getAllProfiles

 public static function getAllProfiles(\PDO $pdo)
 {
     // Create query template and execute
     $query = "SELECT profileId, profileAdmin, profileNameFirst, profileNameLast, profileEmail, profileUserName, profileSalt, profileHash, profileActivationToken FROM profile";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // Build an array of matches
     $profiles = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $profile = new Profile($row["profileId"], $row["profileAdmin"], $row["profileNameFirst"], $row["profileNameLast"], $row["profileEmail"], $row["profileUserName"], $row["profileSalt"], $row["profileHash"], $row["profileActivationToken"]);
             $profiles[$profiles->key()] = $profile;
             $profiles->next();
         } catch (\Exception $exception) {
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $profiles;
 }
开发者ID:ng-abq,项目名称:ng-abq,代码行数:20,代码来源:Profile.php

示例13: getFollowerByFollowedId

 /**
  * gets the Follower relationship by the person being followed
  *
  * @param \PDO $pdo PDO connection object
  * @param int $followerFollowedId the person being followed
  * @return \SplFixedArray SplFixedArray of Follower relationships found or null if not found
  * @throws \PDOException when mySQL related errors occur
  * @throws \TypeError when variables are not the correct data type
  **/
 public static function getFollowerByFollowedId(\PDO $pdo, int $followerFollowedId)
 {
     //Sanitize the followed id
     if ($followerFollowedId <= 0) {
         throw new \PDOException("Get Follower by Followed: Followed Id is not positive");
     }
     //Create a query template
     $query = "SELECT followerFollowerId, followerFollowedId FROM follower WHERE followerFollowedId = :followerFollowedId";
     $statement = $pdo->prepare($query);
     //Search based on the one being followed
     $parameters = ["followerFollowedId" => $followerFollowedId];
     $statement->execute($parameters);
     //Build an array of follower relationships
     $followers = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $follower = new Follower($row["followerFollowerId"], $row["followerFollowedId"]);
             $followers[$followers->key()] = $follower;
             $followers->next();
         } catch (\Exception $exception) {
             //If the row couldn't be converted, rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $followers;
 }
开发者ID:davidmancini,项目名称:jpegery,代码行数:36,代码来源:Follower.php

示例14: getFavoriteTeamsByFavoriteTeamProfileId

 /**
  * gets the list of this profiles favorite teams
  *
  * @param \PDO $pdo connection object
  * @param int $allFavoriteTeams search for
  * @return \SplFixedArray SplFixedArray of all teams favorited found
  * @throws \PDOException when db related errors occur
  * @throws \TypeError when variables are not correct data type
  **/
 public static function getFavoriteTeamsByFavoriteTeamProfileId(\PDO $pdo, int $favoriteTeamProfileId)
 {
     // sanitize the favoriteTeamProfileId
     if ($favoriteTeamProfileId <= 0) {
         throw new \PDOException("that profile doesnt exist");
     }
     // create a query template
     $query = "SELECT favoriteTeamProfileId, favoriteTeamTeamId FROM favoriteTeam WHERE favoriteTeamProfileId = :favoriteTeamProfileId";
     $statement = $pdo->prepare($query);
     // bind the favoriteTeamTeamId to the place holder in the template
     $parameters = ["favoriteTeamProfileId" => $favoriteTeamProfileId];
     $statement->execute($parameters);
     // build an array of favorite teams
     $favoriteTeams = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $favoriteTeam = new FavoriteTeam($row["favoriteTeamProfileId"], $row["favoriteTeamTeamId"]);
             $favoriteTeams[$favoriteTeams->key()] = $favoriteTeam;
             $favoriteTeams->next();
         } catch (\Exception $exception) {
             // if the row can't be converted, rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $favoriteTeams;
 }
开发者ID:chrispaul3625,项目名称:sprots,代码行数:36,代码来源:FavoriteTeam.php

示例15: getTrailByTrailUuid

 public static function getTrailByTrailUuid(PDO &$pdo, $trailUuid)
 {
     //sanitize the trailUuid before searching
     try {
         $trailUuid = Filter::filterString($trailUuid, "trailUuid");
     } catch (InvalidArgumentException $invalidArgument) {
         throw new PDOException($invalidArgument->getMessage(), 0, $invalidArgument);
     } catch (RangeException $range) {
         throw new PDOException($range->getMessage(), 0, $range);
     } catch (Exception $exception) {
         throw new PDOException($exception->getMessage(), 0, $exception);
     }
     //create query template
     $query = "SELECT trailId, userId, browser, createDate, ipAddress, submitTrailId, trailAmenities, trailCondition,trailDescription, trailDifficulty, trailDistance, trailName, trailSubmissionType,\ntrailTerrain, trailTraffic, trailUse, trailUuid FROM trail WHERE trailUuid = :trailUuid";
     $statement = $pdo->prepare($query);
     //bind trailUuid to placeholder
     $parameters = array("trailUuid" => $trailUuid);
     $statement->execute($parameters);
     //build an array of trails
     $trails = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             //new trail ($trailId, $userId, $submitTrailId, $browser, $createDate, $ipAddress, $trailAccessibility, $trailAmenities, $trailCondition,$trailDescription, $trailDifficulty, $trailDistance, $trailSubmissionType,$trailTerrain, $trailName, $trailTraffic, $trailUse, $trailUuId)
             $trail = new Trail($row["trailId"], $row["userId"], $row["browser"], $row["createDate"], $row["ipAddress"], $row["submitTrailId"], $row["trailAmenities"], $row["trailCondition"], $row["trailDescription"], $row["trailDifficulty"], $row["trailDistance"], $row["trailName"], $row["trailSubmissionType"], $row["trailTerrain"], $row["trailTraffic"], $row["trailUse"], $row["trailUuid"]);
             $trails[$trails->key()] = $trail;
             $trails->next();
         } catch (Exception $e) {
             //if the row couldn't be converted, rethrow it
             throw new PDOException($e->getMessage(), 0, $e);
         }
     }
     return $trails;
 }
开发者ID:jmsaul,项目名称:open-trails,代码行数:34,代码来源:trail.php


注:本文中的SplFixedArray::key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。