小编don*_*ame的帖子

php preg_match_all返回数组数组

我想替换一些模板标签:

$tags = '{name} text {first}';
preg_match_all('~\{(\w+)\}~', $tags, $matches);
var_dump($matches);
Run Code Online (Sandbox Code Playgroud)

输出是:

array(2) { 
          [0]=> array(2) { 
                         [0]=> string(6) "{name}" 
                         [1]=> string(7) "{first}" 
                         } 
          [1]=> array(2) { 
                         [0]=> string(4) "name" 
                         [1]=> string(5) "first" 
                         }
         }
Run Code Online (Sandbox Code Playgroud)

为什么有2个阵列?如何实现只有第二个?

php regex

3
推荐指数
1
解决办法
1320
查看次数

范围内的二叉搜索树过滤值

我有一个由 N 个元素组成的树(RBT)。假设我有这棵树(N = 7):

           4
    2             6
1       3      5     7
Run Code Online (Sandbox Code Playgroud)

如何以比 O(N) 更好的性能过滤某个范围内的值(例如打印 3 到 6 之间的所有值)?

有没有具体的算法?我想象它类似于找到值 3 [log(N)] 的位置,以某种方式继续,直到到达 6 [O(M)]。

algorithm search traversal binary-search-tree

3
推荐指数
1
解决办法
3380
查看次数

控制器中的 angular.js 表单验证

我得到了这个表格:

<form ng-controller="SomeCtrl as some" name="product[[product.id]]" ng-submit="some.addToCart(something, product[[product.id]].$valid)" novalidate></form>
Run Code Online (Sandbox Code Playgroud)

然后 html 看起来像:

<form ng-controller="SomeCtrl as some" name="product1" ng-submit="some.addToCart(something, product1.$valid)" novalidate=""></form>
Run Code Online (Sandbox Code Playgroud)

控制器:

this.addToCart = function(something, isValid) {
    console.log(isValid);
}
Run Code Online (Sandbox Code Playgroud)

isValid 总是undefined。如何检测表单在控制器中是否有效?

angularjs

2
推荐指数
1
解决办法
1568
查看次数

jquery查找id高于某个数字的div

有什么办法可以找到它吗?例如:

var number=5;
$("#"+>number).remove();
Run Code Online (Sandbox Code Playgroud)

但我不知道如何做类似的事情,如果有可能:) 谢谢

jquery

0
推荐指数
1
解决办法
1465
查看次数

laravel插入多个表

我有2张桌子

#something - id, name, url
#something_users - id, id_something, email, password
Run Code Online (Sandbox Code Playgroud)

我的模特

class Something extends Eloquent
{

    protected $table = 'something';

    protected $fillable = ['name', 'email', 'password'];

    public $errors;


    public function User()
    {
        return $this->belongsTo('User', 'id', 'id_something');
    }
}

class User extends Eloquent implements UserInterface, RemindableInterface {

    use UserTrait, RemindableTrait;


    protected $table = 'something_users';

    protected $hidden = array('password', 'remember_token');

    public function Something()
    {
        return $this->belongsTo('Something');
    }

}
Run Code Online (Sandbox Code Playgroud)

调节器

$input = Input::all();

// also some validation
$this->db->fill($input);

$this->db->password = Hash::make(Input::get('password')); …
Run Code Online (Sandbox Code Playgroud)

php laravel

0
推荐指数
1
解决办法
3万
查看次数