Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Multi-Dimensional Array: Finding a multi-element sub-array match ... is there an alternate option to looping?
    primarykey
    data
    text
    <p>We have some customer data which started in a separate data-store. I have a consolidation script to standardize and migrate it into our core DB. There are somewhere around 60,000-70,000 records being migrated.</p> <p>Naturally, there was a little bug, and it failed around row 9k.<br> My next trick is to make the script able to pick up where it left off when it is run again.</p> <p><br> <strong>FYI:</strong><br> The source records are pretty icky, and split over 5 tables by what brand they purchased ... IE:<br></p> <pre><code>create TABLE `brand1_custs` (`id` int(9), `company_name` varchar(112), etc...) create TABLE `brand2_custs` (`id` int(9), `company_name` varchar(112), etc...) </code></pre> <p>Of course, a given company name can (and does) exist in multiple source tables.</p> <p><br> <strong>Anyhow ...</strong> I used the ParseCSV lib for logging, and each row gets logged if successfully migrated (some rows get skipped if they are just too ugly to parse programatically). When opening the log back up with ParseCSV, it comes in looking like:</p> <pre><code>array( 0 =&gt; array( 'row_id' =&gt; '1', 'company_name' =&gt; 'Cust A', 'blah' =&gt; 'blah', 'source_tbl' =&gt; 'brand1_cust' ), 1 =&gt; array( 'row_id' =&gt; '2', 'company_name' =&gt; 'customer B', 'blah' =&gt; 'blah', 'source_tbl' =&gt; 'brand1_cust' ), 2 =&gt; array( 'row_id' =&gt; '1', 'company_name' =&gt; 'Cust A', 'blah' =&gt; 'blah', 'source_tbl' =&gt; 'brand2_cust' ), etc... ) </code></pre> <p><br> <strong>My current workflow</strong> is along the lines of:</p> <pre><code>foreach( $source_table AS $src){ $results = // get all rows from $src foreach($results AS $row){ // heavy lifting { } </code></pre> <p><br> <strong>My Plan</strong> is to check the <br> <code>$row-&gt;id</code> and <code>$src-&gt;tbl</code> combination <br> for a match in the <br> <code>$log[?x?]['row_id']</code> and <code>$log[?x?]['source_tbl']</code> combination.</p> <p>In order to achieve that, I would have to do a <code>foreach($log AS $xyz)</code> loop <strong><em>inside</em></strong> the <code>foreach($results AS $row)</code> loop, and skip any rows which are found to have already been migrated (otherwise, they would get duplicated).<br> That seems like a <strong>LOT</strong> of of looping to me.<br> What about when we get up around record # 40 or 50 thousand?<br> That would be 50k x 50k loops!!</p> <p><strong>Question:</strong><br> Is there a better way for me to check if a sub-array has a "row_id" and "source_tbl" match <em>other</em> than looping each time?</p> <p><br> <strong>NOTE:</strong> as always, if there's a <em><strong>completely</strong></em> different way I should be thinking about this, I'm open to any and all suggestions :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload