/**
  * @covers ::array_merge_keys
  * @dataProvider provideArraysToMerge
  */
 public function testCanMergeTwoArrays($target, $extra, $expectedResult)
 {
     // ----------------------------------------------------------------
     // setup your test
     // ----------------------------------------------------------------
     // perform the change
     $actualResult = array_merge_keys($target, $extra);
     // ----------------------------------------------------------------
     // test the results
     $this->assertEquals($expectedResult, $actualResult);
 }
Esempio n. 2
0
 public function actionDefault()
 {
     $posts = array((int) strtotime('February 17 2010 1:36am') => array('title' => 'An interesting title for a much less interesting, and much less interesting it is, story', 'created' => 'February 17 2010 1:36am', 'channel' => 'Official News', 'comments' => 4, 'rating' => 9, 'text' => 'Those singers lent her a lot of money. They tell them a joke. Bruce granted him his wish. That car mechanic promises her a new house. That farmer buys him a present. They tell them a joke.
                Those dentists asked him a question. They struck him a heavy blow. Luke gives him a magazine. I envied him his good fortune.
                Those singers lent her a lot of money. They tell them a joke. Bruce granted him his wish. That car mechanic promises her a new house. That farmer buys him a present. They tell them a joke.
                They struck him a heavy blow. Luke gives him a magazine. They struck him a heavy blow. Luke gives him a magazine. They struck him a heavy blow. Luke gives him a magazine. They struck him a heavy blow. Luke gives him a magazine. They struck him a heavy blow. Luke gives him a magazine. I envied him his good fortune.
                They struck him a heavy blow. Luke gives him a magazine. I envied him his good fortune. I wrote her a letter. Those dentists asked him a question. They struck him a heavy blow. Luke gives him a magazine. I envied him his good fortune.'), (int) strtotime('January 16 2010 1:12am') => array('title' => 'This is a main news feed, describing the subject matter', 'created' => 'January 16 2010 1:12am', 'channel' => 'Official News', 'comments' => 21, 'rating' => 7, 'text' => 'Those singers lent her a lot of money. They tell them a joke. Bruce granted him his wish. That car mechanic promises her a new house. That farmer buys him a present. They tell them a joke.
                Those dentists asked him a question. They struck him a heavy blow. Luke gives him a magazine. I envied him his good fortune.
                They struck him a heavy blow. Luke gives him a magazine. I envied him his good fortune. I wrote her a letter. Those dentists asked him a question. They struck him a heavy blow. Luke gives him a magazine. I envied him his good fortune.'), (int) strtotime('February 15 2010 6:37pm') => array('title' => 'Well here is another stupid heading to show the dynamic nature of this page layout, as this header is very long', 'created' => 'February 15 2010 6:37pm', 'channel' => 'Official News', 'comments' => 6, 'rating' => -11, 'text' => 'Those singers lent her a lot of money. They tell them a joke. Bruce granted him his wish. That car mechanic promises her a new house. That farmer buys him a present. They tell them a joke.
                Those dentists asked him a question. They struck him a heavy blow. Luke gives him a magazine. I envied him his good fortune. I wrote her a letter. Those dentists asked him a question. They struck him a heavy blow. Luke gives him a magazine. I envied him his good fortune.'), (int) strtotime('February 12 2010 5:49pm') => array('title' => 'Well here is another stupid heading to show the dynamic nature of this page layout, as this header is very long', 'created' => 'February 12 2010 5:49pm', 'channel' => 'Official News', 'comments' => 37, 'rating' => 38, 'text' => 'Those singers lent her a lot of money. They tell them a joke. Bruce granted him his wish. That car mechanic promises her a new house. That farmer buys him a present. They tell them a joke.
                Those dentists asked him a question. They struck him a heavy blow. Luke gives him a magazine. I envied him his good fortune. I wrote her a letter. Those dentists asked him a question. They struck him a heavy blow. Luke gives him a magazine. I envied him his good fortune.'));
     $twitter_posts = $this->_getLatestTwitter();
     $all_posts = array_merge_keys(array(), $posts);
     //print_r($all_posts);
     krsort($all_posts, SORT_NUMERIC);
     //print_r($all_posts);
     $this->getTemplate()->body->all_posts = $all_posts;
 }
 /**
  * create the format string and exception data
  *
  * @param  string $builder
  *         name of the ParameterBuilder class to use
  * @param  string $formatString
  *         the format string to customise
  * @param  array $backtrace
  *         a debug_backtrace()
  * @param  mixed $fieldOrVar
  *         the value that you're throwing an exception about
  * @param  string $fieldOrVarName
  *         the name of the value in your code
  * @param  array $extraData
  *         extra data that you want to include in your exception
  * @param  int|null $typeFlags
  *         do we want any extra type information in the final exception message?
  * @param  array $callStackFilter
  *         are there any namespaces we want to filter out of the call stack?
  * @return ParameterisedException
  *         an fully-built exception for you to throw
  */
 protected static function buildFormatAndData($builder, $formatString, $backtrace, $fieldOrVar, $fieldOrVarName, array $extraData = [], $typeFlags = null, array $callStackFilter = [])
 {
     // build the basic message and data
     list($message, $data) = $builder::from($formatString, $backtrace, $callStackFilter);
     // merge in any extra data we've been given
     $data = array_merge_keys($data, $extraData);
     // merge in the remainder of our parameters
     $data['dataType'] = GetPrintableType::of($fieldOrVar, $typeFlags);
     $data['fieldOrVarName'] = $fieldOrVarName;
     $data['fieldOrVar'] = $fieldOrVar;
     // all done
     return [$message, $data];
 }
function array_merge_keys($arr1, $arr2)
{
    foreach ($arr2 as $k => $v) {
        if (!array_key_exists($k, $arr1)) {
            //K DOESN'T EXISTS //
            $arr1[$k] = $v;
        } else {
            // K EXISTS //
            if (is_array($v)) {
                // K IS AN ARRAY //
                $arr1[$k] = array_merge_keys($arr1[$k], $arr2[$k]);
            }
        }
    }
    return $arr1;
}