title: search in PHP Array, similar to MySQL Like %var% search with livewire
body: <p>I saw other questions that usually use <code>preg_grep</code> but my problem was not solved
  In the LiveWire component, I receive information from the web service and display it in a table.
  Now the user does the search and I want to display the items that look like the searched phrase</p>
  <p>I wrote the code like this:</p>
  <pre><code>class Cryptolist extends Component
  {
      use WithPagination;
      public bool $loadData = false;
      protected $paginationTheme = 'bootstrap';
      public $perPage = 10;
      public $search = '';
  
      public function init()
      {
          $this-&gt;loadData = true;
      }
  
      public function getBalance($asset)
      {
              $this-&gt;dispatchBrowserEvent('setPrice' ,[
                  'asset' =&gt; $asset,
                  'price' =&gt; getCryptoBalance($asset)
              ]);
      }
      
  
      public function setPerPage(int $page)
      {
          $this-&gt;perPage = $page;
      }
  
      public function render()
      {
          try {
              if ($this-&gt;loadData == true) {
                  $api = new \Binance\API('','');
                  $coins = $api-&gt;coins();
              } else {
                  $coins = [];
              }
              return view('livewire.backend.crypto.cryptolist')-&gt;with('coins' , collect(preg_grep('~'.$this-&gt;search.'~i', $coins))-&gt;paginate($this-&gt;perPage));
          }catch(\Exception $e)
          {
              return view('wrong')-&gt;with('e' , $e);
          }
      }
  }
  </code></pre>
  <p>and this is view:</p>
  <pre><code>&lt;div class=&quot;nk-block&quot; id=&quot;loadesh1&quot; &gt;
      &lt;div class=&quot;card card-bordered card-stretch&quot;&gt;
          &lt;div class=&quot;card-inner-group&quot;&gt;
              &lt;div class=&quot;card-inner position-relative card-tools-toggle&quot;&gt;
                  &lt;div class=&quot;card-title-group&quot;&gt;
                      &lt;div class=&quot;card-tools mr-n1&quot;&gt;
                          &lt;ul class=&quot;btn-toolbar gx-1&quot;&gt;
                              &lt;li&gt;
                                  &lt;a class=&quot;btn btn-icon search-toggle toggle-search&quot; data-target=&quot;search&quot; href=&quot;#&quot;&gt;&lt;em class=&quot;icon ni ni-search&quot;&gt;&lt;/em&gt;&lt;/a&gt;
                              &lt;/li&gt;
                              &lt;li class=&quot;btn-toolbar-sep&quot;&gt;&lt;/li&gt;
                              &lt;li&gt;
                                  &lt;div class=&quot;toggle-wrap&quot;&gt;
                                      &lt;a class=&quot;btn btn-icon btn-trigger toggle&quot; data-target=&quot;cardTools&quot; href=&quot;#&quot;&gt;&lt;em class=&quot;icon ni ni-menu-right&quot;&gt;&lt;/em&gt;&lt;/a&gt;
                                      &lt;div class=&quot;toggle-content&quot; data-content=&quot;cardTools&quot;&gt;
                                          &lt;ul class=&quot;btn-toolbar gx-1&quot;&gt;
                                              &lt;li class=&quot;toggle-close&quot;&gt;
                                                  &lt;a class=&quot;btn btn-icon btn-trigger toggle&quot; data-target=&quot;cardTools&quot; href=&quot;#&quot;&gt;&lt;em class=&quot;icon ni ni-arrow-left&quot;&gt;&lt;/em&gt;&lt;/a&gt;
                                              &lt;/li&gt;
                                              &lt;li&gt;
                                                  &lt;div class=&quot;dropdown&quot;&gt;
                                                      &lt;a class=&quot;btn btn-trigger btn-icon dropdown-toggle&quot; data-toggle=&quot;dropdown&quot; href=&quot;#&quot;&gt;&lt;em class=&quot;icon ni ni-setting&quot;&gt;&lt;/em&gt;&lt;/a&gt;
                                                      &lt;div class=&quot;dropdown-menu dropdown-menu-xs dropdown-menu-right&quot;&gt;
                                                          &lt;ul class=&quot;link-check&quot;&gt;
                                                              &lt;li&gt;&lt;span&gt;show&lt;/span&gt;&lt;/li&gt;
                                                              &lt;li @if($perPage === 10) class=&quot;active&quot; @endif&gt;
                                                                  &lt;a href=&quot;#&quot; wire:click.prevent=&quot;setPerPage(10)&quot;&gt;10&lt;/a&gt;
                                                              &lt;/li&gt;
                                                              &lt;li @if($perPage === 20) class=&quot;active&quot; @endif&gt;
                                                                  &lt;a href=&quot;#&quot;wire:click.prevent=&quot;setPerPage(20)&quot;&gt;20&lt;/a&gt;
                                                              &lt;/li&gt;
                                                              &lt;li @if($perPage === 50) class=&quot;active&quot; @endif&gt;
                                                                  &lt;a href=&quot;#&quot; wire:click.prevent=&quot;setPerPage(50)&quot;&gt;50&lt;/a&gt;
                                                              &lt;/li&gt;
                                                          &lt;/ul&gt;
                                                      &lt;/div&gt;
                                                  &lt;/div&gt;
                                              &lt;/li&gt;
                                          &lt;/ul&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/li&gt;
                          &lt;/ul&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;card-search search-wrap&quot; data-search=&quot;search&quot;&gt;
                      &lt;div class=&quot;card-body&quot;&gt;
                          &lt;div class=&quot;search-content&quot;&gt;
                              &lt;a class=&quot;search-back btn btn-icon toggle-search&quot; data-target=&quot;search&quot; href=&quot;#&quot;&gt;&lt;em class=&quot;icon ni ni-arrow-left&quot;&gt;&lt;/em&gt;&lt;/a&gt;&lt;input wire:model=&quot;search&quot; class=&quot;form-control border-transparent form-focus-none&quot; placeholder=&quot;type for search&quot; type=&quot;text&quot;&gt;&lt;button class=&quot;search-submit btn btn-icon&quot;&gt;&lt;em class=&quot;icon ni ni-search&quot;&gt;&lt;/em&gt;&lt;/button&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;card-inner p-0&quot; wire:init=&quot;init&quot;&gt;
                  &lt;div class=&quot;nk-tb-list nk-tb-ulist&quot;&gt;
                      &lt;div class=&quot;nk-tb-item nk-tb-head&quot;&gt;
                          &lt;div class=&quot;nk-tb-col&quot;&gt;
                              &lt;span class=&quot;sub-text&quot;&gt;name&lt;/span&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;nk-tb-col tb-col-mb&quot;&gt;
                              &lt;span class=&quot;sub-text&quot;&gt;balance&lt;/span&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      @foreach ($coins as $item =&gt; $value)
                          &lt;div class=&quot;nk-tb-item&quot;&gt;
                              &lt;div class=&quot;nk-tb-col&quot;&gt;
                                  &lt;a href=&quot;/demo5/user-details-regular.html&quot;&gt;
                                      &lt;div class=&quot;user-card&quot;&gt;
                                          &lt;div class=&quot;user-avatar d-none d-sm-flex&quot;&gt;
  
                                              @if(file_exists(public_path() . '/img/crypto/'.strtolower($value['coin'].&quot;.svg&quot;)))
                                                  &lt;img style=&quot;border-radius: 0&quot; src=&quot;{{asset('/img/crypto/'.strtolower($value['coin']))}}.svg&quot; class=&quot;img-fluid&quot; alt=&quot;&quot;&gt;
                                              @else
                                                  &lt;img style=&quot;border-radius: 0&quot; src=&quot;https://demo.rayanscript.ir/-/vendor/cryptocurrency-icons/32/color/noimage.png&quot; class=&quot;img-fluid&quot; alt=&quot;&quot;&gt;
                                              @endif
  
                                          &lt;/div&gt;
                                          &lt;div class=&quot;user-info&quot;&gt;
                                              &lt;span class=&quot;tb-lead english&quot; style=&quot;font-weight: bolder&quot;&gt;{{$value['name']}}&lt;/span&gt;
                                              &lt;span class=&quot;english&quot;&gt;{{$value['coin']}}&lt;/span&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                  &lt;/a&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;nk-tb-col tb-col-mb&quot;&gt;
                                  &lt;div class=&quot;btn-group&quot; aria-label=&quot;Basic example&quot;&gt;
                                      &lt;button type=&quot;button&quot; class=&quot;btn btn-sm btn-dim btn-light&quot; wire:click=&quot;getBalance('{{$value['coin']}}')&quot;&gt;
                                          &lt;div wire:loading wire:target=&quot;getBalance('{{$value['coin']}}')&quot;&gt;
                                              &lt;span class=&quot;spinner-border spinner-border-sm&quot; role=&quot;status&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;
                                          &lt;/div&gt;
                                          &lt;span class=&quot;w-120px&quot; id=&quot;coin-{{$value['coin']}}&quot;&gt;get balance&lt;/span&gt;
                                      &lt;/button&gt;
                                      &lt;button type=&quot;button&quot; class=&quot;btn btn-sm btn-dim btn-primary&quot;&gt;add coin&lt;/button&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      @endforeach
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>But this error is given. Is my search method correct?</p>
  <pre><code>Array to string conversion
  
  </code></pre>