Please help. Something stumbled with the understanding of arrays. There is a request:

$q = $modx->newQuery('modContext'); $where = array( 'modContext.key:in' => array('web', 'mgr'), 'cs.value:!=' => NULL, 'cs.value:!=' => '', ); $q->select(array( 'modContext.key', 'cs.key as setting_key', 'cs.value' )); $q->innerJoin('modContextSetting', 'cs', 'cs.context_key = modContext.key'); $q->where($where); 

where is assigned at a time. How to break this action into several. Type:

 $where['modContext.key:in'] => 'web'; $where['modContext.key:in'] => 'mgr'; $where['cs.value:!='] => NULL; $where['cs.value:!='] => ''; 

Help me please.

  • In general, I need to make sure that where was going along the code, and then used in two different requests. For this, it is necessary that the where elements are added along with the terms "like", "in", etc. I only succeeded in overlapping each other, where in the end only the last element in the array remained. - Ruslan

1 answer 1

Like this:

 $where = []; //инициализация пустого массива, чтобы можно было присваивать значения через индексаторы //... do something ... $where['modContext.key:in'] = ['web', 'mgr']; //... do something ... $where['cs.value:!='] = null; //... do something ... $where['cs.value:!='] = ''; //обратите внимание, эта строчка перезапишет предыдущую, т.е. у Вас в массиве останется два значения, а не три //Дальше как и у Вас: $q->select(array( 'modContext.key', 'cs.key as setting_key', 'cs.value' )); $q->innerJoin('modContextSetting', 'cs', 'cs.context_key = modContext.key'); $q->where($where); 
  • Here I am a burdock ... Instead of "=" he wrote "=>". Thank you very much, kind man) - Ruslan
  • one
    It's my pleasure. Such an error can be avoided using a code editor with syntax highlighting. The editor will tell you if you make a syntax error. - A1essandro