小编fuz*_*lop的帖子

php从数组删除元素

我使用cakephp 2.0并且我提交的数据我要清理,数组结构如下我如何删除其中quantity = null的元素(quoteitem)?

我有这个,但它不起作用;

foreach($this->request->data['Quoteitem'] as $qi) {
 if($qi['quantity']==null){
 echo 'quantity is null,delete this quote item from array';                 
 unset($qi);
}       
}
Run Code Online (Sandbox Code Playgroud)

被称为数组的结构($ this-> request-> data)

Array
(
    [Quote] => Array
        (
            [customer_id] => 72
            [user_id] => 104                
        )

    [Range] => Array
        (
            [id] => 
        )

    [Quoteitem] => Array
        (
            [0] => Array
                (
                    [product_id] => 
                    [unitcost] => 
                    [quantity] => 1
                )

            [1] => Array
                (
                    [product_id] => 
                    [unitcost] => 
                    [quantity] => 22
                )

            [2] => Array
                (
                    [product_id] => …
Run Code Online (Sandbox Code Playgroud)

php cakephp

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

Saveall不工作

我正在使用cake 2.0.6并且我试图保存多个记录,这些记录是我从表单输出数据的产品;

我不能保存两个记录,我的表格中的字段设置为; 0是它应该保存的第一条记录.由于某种原因,它不会保存2条记录.我已经关闭了产品型号的所有验证,并且没有presave方法

任何想法都错了吗?

<input name="data[Product][0][product_code]"/>
<input name="data[Product][0][colour]"/>
<input name="data[Product][0][lead_time_weeks]"/>
<input name="data[Product][0][description]"/>
<input name="data[Product][0][height]" />
<input name="data[Product][0][width]" />
<input name="data[Product][0][depth]" />
<input name="data[Product][0][price]" />
<input name="data[Product][0][discount]" />
<input name="data[Product][0][discounted_price]" />
<input name="data[Product][0][quantity]"/>


<input name="data[Product][1][product_code]"/>
<input name="data[Product][1][colour]"/>
<input name="data[Product][1][lead_time_weeks]"/>
<input name="data[Product][1][description]"/>
<input name="data[Product][1][height]" />
<input name="data[Product][1][width]" />
<input name="data[Product][1][depth]" />
<input name="data[Product][1][price]" />
<input name="data[Product][1][discount]" />
<input name="data[Product][1][discounted_price]" />
<input name="data[Product][1][quantity]"/>


Array
(
    [Product] => Array
        (
            [0] => Array
                (
                    [product_code] => fgfgf
                    [colour] => 
                    [lead_time_weeks] => 
                    [description] => …
Run Code Online (Sandbox Code Playgroud)

cakephp cakephp-2.0

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

如何解析字符串

我试图解析以下字符串;

"data[Product][0][fieldname]"
Run Code Online (Sandbox Code Playgroud)

我需要能够将"[0]"部分更改为数字,"数据[产品]"不会更改,而"[fieldname]"将更改.

我不知道如何使用javascript,但有一个粗略的想法.

我所有的错误,在下面,但因为[0]每次都不起作用;

name="data[Product][0][fieldname]";
name.replace('[0]', '['+newrowid+']'
Run Code Online (Sandbox Code Playgroud)

的jsfiddle; http://jsfiddle.net/fuzzy_dunlop/8WKcs/

javascript string replace

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

标签 统计

cakephp ×2

cakephp-2.0 ×1

javascript ×1

php ×1

replace ×1

string ×1