Using a Hash function to set field across multiple rows in a CakePHP array

StackOverflow https://stackoverflow.com/questions/21670293

  •  09-10-2022
  •  | 
  •  

سؤال

What I'm trying to achieve is something like this:

Hash::set($result, 'Model.{n}.field', 'replacementvalue');

But there doesn't seem to be a function in the hash class that does this. How can I achieve this without a foreach loop?

Edit: made it more clear I'm replacing a value not setting a new one

هل كانت مفيدة؟

المحلول

$result = Hash::insert($result, 'Model.{n}.field', 'newvalue')

seems to do exactly what you're asking

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top