예제 #1
0
파일: StrTest.php 프로젝트: brianseitel/ook
 public function testStrReplaceFirst()
 {
     $key = 'foo.*.bar.*';
     $results = Str::strReplaceFirst('*', '0', $key);
     $this->assertEquals('foo.0.bar.*', $results);
     $results = Str::strReplaceFirst('no', '0', $results);
     $this->assertEquals('foo.0.bar.*', $results);
 }
예제 #2
0
파일: Arr.php 프로젝트: brianseitel/ook
 /**
  * Accepts a dot-notation array key with wildcards and expands them
  * into an array of dot-notation array keys in numerical order.
  *
  * @param string $key - dot notation
  * @param int $size - number of keys to generate per wildcard. Defaults to 10.
  * @return array
  */
 public static function expandKeys($key, $size = 10)
 {
     $keys = [];
     $original_key = $key;
     for ($i = 0; $i < $size; $i++) {
         $k = Str::strReplaceFirst('*', $i, $original_key);
         if (strpos($k, '*') !== false) {
             $sub_keys = static::expandKeys($k, $size);
             foreach ($sub_keys as $sk) {
                 $keys[] = $sk;
             }
         } else {
             $keys[] = $k;
         }
     }
     return $keys;
 }