0

I am trying to set string in foreach loop using =>. Problem is, if I use => operator then string create correctly and generate error... please help me... my sample code is

$field = array();
    $cond = array();
    foreach ($fields as $val) {
        $field[] = $model.'.'.$val;
        $cond[] = $model.'.'.$val.' '.'LIKE '.=>."%".$value."%";
    }

I have generate string like

'or'=>array('ErpProduct.ProductCode LIKE'=>"%".$value."%",'ErpProduct.ProductName LIKE'=>"%".$value."%"),
2
  • Enclose it in the quote...? Why do you need => there in the first place? Commented Mar 25, 2014 at 5:15
  • 1
    for cakephp query standard Commented Mar 25, 2014 at 5:19

1 Answer 1

2

There is no => operator in php, => is used in the array literal.

What you should do is just setting it as array index like below:

foreach ($fields as $val) {
   $field[] = $model.'.'.$val;
   $cond[$model.'.'.$val.' '.'LIKE '] = "%".$value."%";
}
Sign up to request clarification or add additional context in comments.

1 Comment

If I setting it as array index then it gives Array ( [ErpProduct.ProductCode LIKE ] => %Atish% [ErpProduct.ProductName LIKE ] => %Atish% ) which is genearte error in cakephp query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.