PHP - Iptcembed & Keywords Array
Ok, so first, I'm a little more experienced than a newb, but far from an expert. And I'm fairly certain when yall help me through this I'm going to bang my head on the desk and chastize myself for not thinking of it. So here we go.
I'm attempting to use some examples I found on php.net for the iptc embed & iptcparse functions. What I've done is taken a class file that was posted (just a collection of the snippets), corrected it for the most part to function how it should. It will read the IPTC data from a jpg just fine. It'll even write to the IPTC fields. The problem comes with the IPTC_KEYWORDS field. That field needs to be an array and I can't get it to write properly. Right now the only thing it's writing is the word "array". Also, I'm a bit confused as to what one of the functions is trying to do and I think it's the function that's causing the mess. Below are the classfile and then the test file making the call. Code: [Select] <? /* Examples taken from php.net */ DEFINE('IPTC_OBJECT_NAME', '005'); DEFINE('IPTC_EDIT_STATUS', '007'); DEFINE('IPTC_PRIORITY', '010'); DEFINE('IPTC_CATEGORY', '015'); DEFINE('IPTC_SUPPLEMENTAL_CATEGORY', '020'); DEFINE('IPTC_FIXTURE_IDENTIFIER', '022'); DEFINE('IPTC_KEYWORDS', '025'); DEFINE('IPTC_RELEASE_DATE', '030'); DEFINE('IPTC_RELEASE_TIME', '035'); DEFINE('IPTC_SPECIAL_INSTRUCTIONS', '040'); DEFINE('IPTC_REFERENCE_SERVICE', '045'); DEFINE('IPTC_REFERENCE_DATE', '047'); DEFINE('IPTC_REFERENCE_NUMBER', '050'); DEFINE('IPTC_CREATED_DATE', '055'); DEFINE('IPTC_CREATED_TIME', '060'); DEFINE('IPTC_ORIGINATING_PROGRAM', '065'); DEFINE('IPTC_PROGRAM_VERSION', '070'); DEFINE('IPTC_OBJECT_CYCLE', '075'); DEFINE('IPTC_BYLINE', '080'); DEFINE('IPTC_BYLINE_TITLE', '085'); DEFINE('IPTC_CITY', '090'); DEFINE('IPTC_PROVINCE_STATE', '095'); DEFINE('IPTC_COUNTRY_CODE', '100'); DEFINE('IPTC_COUNTRY', '101'); DEFINE('IPTC_ORIGINAL_TRANSMISSION_REFERENCE', '103'); DEFINE('IPTC_HEADLINE', '105'); DEFINE('IPTC_CREDIT', '110'); DEFINE('IPTC_SOURCE', '115'); DEFINE('IPTC_COPYRIGHT_STRING', '116'); DEFINE('IPTC_CAPTION', '120'); DEFINE('IPTC_LOCAL_CAPTION', '121'); class iptc { var $meta=Array(); var $hasmeta=false; var $file=false; function iptc($filename) { echo 'IPTC Loading for: '.$filename.'<br />'; $size = getimagesize($filename,$info); $this->hasmeta = isset($info["APP13"]); if($this->hasmeta) $this->meta = iptcparse($info["APP13"]); $this->file = $filename; } function set($tag, $data) { echo 'Updating IPTC Tag.<br />'; $this->meta ["2#$tag"]= Array( $data ); $this->hasmeta=true; } function get($tag) { echo 'Getting IPTC data.<br />'; return isset($this->meta["2#$tag"]) ? $this->meta["2#$tag"][0] : false; } function view() { echo 'Print IPTC Data.<br />'; foreach(array_keys($this->meta) as $s) { $c = count ($this->meta[$s]); for ($i=0; $i <$c; $i++) { echo $s.' = '.$this->meta[$s][$i].'<br />'; } } } function binary() { echo 'Setting new binary block for IPTC writing.<br />'; $iptc_new = ''; foreach (array_keys($this->meta) as $s) { $c = count ($this->meta[$s]); for ($i=0; $i <$c; $i++) { $tag = str_replace("2#", "", $s); $iptc_new .= $this->iptc_maketag(2, $tag, $this->meta[$s][$i]); } } return $iptc_new; } function iptc_maketag($rec,$dat,$val) { echo 'Making IPTC Tag<br />'; $len = strlen($val); if ($len < 0x8000) { return chr(0x1c).chr($rec).chr($dat). chr($len >> 8). chr($len & 0xff). $val; } else { return chr(0x1c).chr($rec).chr($dat). chr(0x80).chr(0x04). chr(($len >> 24) & 0xff). chr(($len >> 16) & 0xff). chr(($len >> 8 ) & 0xff). chr(($len ) & 0xff). $val; } } function write() { echo 'Writing file...<br />'; if(!function_exists('iptcembed')) return false; $mode = 0; $content = iptcembed($this->binary(), $this->file, $mode); $filename = $this->file; @unlink($filename); #delete if exists $fp = fopen($filename, "w"); fwrite($fp, $content); fclose($fp); } #requires GD library installed function removeAllTags() { 'Removing previous IPTC tags to re-write new data.<br />'; $this->hasmeta=false; $this->meta=Array(); $img = imagecreatefromstring(implode(file($this->file))); @unlink($this->file); #delete if exists imagejpeg($img,$this->file,100); } }; ?> And here's the test-call: Code: [Select] <?php require_once("iptceasy.php"); $i = new iptc("fortworden.jpg"); $keywords = array( "keywords" => "updatedkey1", "updatedkey2", "updatedkey3" , "updatedkey4" ); echo $i->set(IPTC_KEYWORDS, $keywords); $i->write(); echo 'Done.'; ?> If I try to set any of the other IPTC fields with a string, the functions work fine. I'm fairly certain the error is either in the set() function or the iptc_maketag() function. And the iptc_maketag() function is the one I'm stumped about. Is that binary that it's prepending to the data? Thanks for any light you can shed and help you can give on this in advance! -Mike Similar TutorialsFriends, Requirement: I want to Extract the Keywords from All the Search Engine Referer URLs and save all the keywords in an Array so i can Echo/show all the "popular Terms" which drive traffic to my Site from Search Engines. I already have the Code for Extracting the Keyword from URL, can someone tell me how can i save the $keyword in an array that whenever i visit my site, i can see that What all keywords brought visitors to my site from Search Engines? Code to Extract Keywords from URL: <? $referrer = $_SERVER['HTTP_REFERER']; $referrer ='http://www.google.co.id/search?hl=id&client=firefox-a&hs=IKn&rls=org.mozilla%3Aen-US%3Aofficial&channel=s&q=pemahaman+pelajaran+ips+tentang+endogen+dan+eksogen&aq=f&aqi=&aql=&oq=&gs_rfai='; $referrer_query = parse_url($referrer); $referrer_host = $referrer_query['host']; $referrer_query = $referrer_query['query']; $q = "[q|p|qkw|key|query|searchfor|Keywords|searchterm]"; //Yahoo uses both query strings, I am using switch() for each search engine preg_match('/'.$q.'=(.*?)&/',$referrer,$keyword); $keyword = urldecode($keyword[1]); $potongnya = array('&q=','&p=','key=','query=','searchfor=','Keywords=','searchterm='); $referrer_query = str_replace($potongnya, "&|pencarian=", $referrer_query); $arr = explode("&", "$referrer_query"); for($k = 0, $l = count($arr); $k < $l; ++$k) { $ygdicari = "$arr[$k]"; $findmeyach = "|pencarian="; $posnyaaa = strpos($ygdicari, $findmeyach); if ($posnyaaa === false) {} else { $keyword = str_replace('|pencarian=', "", $ygdicari); $potongkeynya = array('+','%20'); $keyword = str_replace($potongkeynya, " ", $keyword); } } if ($keyword=="") { $potongnya = array('q=','p='); $referrer_query = str_replace($potongnya, "&|pencarian=", $referrer_query); $arr = explode("&", "$referrer_query"); for($k = 0, $l = count($arr); $k < $l; ++$k) { $ygdicari = "$arr[$k]"; $findmeyach = "|pencarian="; $posnyaaa = strpos($ygdicari, $findmeyach); if ($posnyaaa === false) {} else { $keyword = str_replace('|pencarian=', "", $ygdicari); $potongkeynya = array('+','%20'); $keyword = str_replace($potongkeynya, " ", $keyword); } } } $keyword = strtolower($keyword); $urikeyword = array('sex ','porn ','porno',', ','penis ','penis ','http://www.','http://','http','gamble','"',"'"); $keyword = str_replace($urikeyword, "", "$keyword"); echo "$keyword"; exit; ?> Many Thanks Natasha T When I make dynamic thumbnails, they are produced as orphans (ie they have no metadata). I am familiar with ways to get IPTC or EXIF data into such thumbnails if you go and actually write the file to disc, however I have more specific problem related to making them dynamically. Below is a snippet of code that is currently being used // details of orig image list($width, $height) = getimagesize($file); // Resizing the Image (make up new modwith and modheight) $tn = imagecreatetruecolor($modwidth, $modheight); $image = imagecreatefromjpeg($file); imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height); // Outputting a .jpg, imagejpeg($tn, null, 80); What I would like to do is insert some IPTC headers into this exact process without changing the input or output - so the pseudocode for the revised module would be // details of orig image list($width, $height) = getimagesize($file); === GET THE IPTC HEADERS FROM THE ORIGINAL HERE ========= // Resizing the Image $tn = imagecreatetruecolor($modwidth, $modheight); $image = imagecreatefromjpeg($file); imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height); ==RE-INSERT THESE IPTC HEADERS ===== // Outputting a .jpg, imagejpeg($tn, null, 80); If anyone could help that would be most appreciated. As regards getting the IPTC headers, clearly the php command iptcparse is the one, however I cannot get iptcembed to work. Many thanks I currently have three tables Domains Keywords Words In words I would have Sport Football Rugby And allocate them to the domain in keywords, but say I wanted Rugby League, would I have an entry in words as Rugby League or two seperate entries rugby and league? And how would i combine them in the keywords table? Keywords_id Keywords_domain Keywords_word Thanks Hi is it possible to take a list of keywords like (web design, oldham web design) and compare it to a large amount of text and output how many times the keywords appear? Hello, I'm working on a file upload/download setup. I want the MySQL table to be arranged like so: id----int(11)----primary key Filename----varchar(30) Keyword1----varchar(30) Keyword2----varchar(30) Description----text DateAdded----timestampCURRENT_TIMESTAMP Type----varchar(30) Size----int(11) Content----mediumblob My question is; Is there a way to make the users select their keywords from a predetermined list (i.e. a dropdown menu) rather than letting them just punch in whatever keywords they want? Hi, im new to the forum and also to php, ive had a look through the tutorials and various threads but cant seem to find what im after. im created a simply image gallery that auto creates my thumbnails and allows for editing the image with gdlibrary etc all very good here. I recently decided to start work on the image keyword tagging so i could carry out searches etc on my very large image collection. i created the usual 3 table setup as im going to have a many to many relationship, so i have my "images" table, "keywords" table and a "img_key" table to link them together. As i understand it this would seem like the best setup for what i want to achieve, if not would someone be able to advise what i should be doing to get better results. Ok so the main problem i have now is that i want to show a series of check boxes underneath each image that gets selected so i can start tagging the uploaded images, to do this i used "select * from keywords" which gave me all keywords available - which is what i want...... However, i now want to somehow add to this so that once the page loads it knows which keywords have already been selected and ticks the relevant boxes automatically, as I have an sql update statement linked to the tickboxes/submit button i want to ensure i dont forget to re-tick any boxes So in a nutshell i need help with displaying all keywords each as a tickbox and if they have already been linked in my 'img_key' link table then they will tick the related tick box automatically , depending on what i need to change im guessing i may need to revise my updating of mysql ? ive been struggling with this silly problem now for a few weeks so im desperate for some assistance Folks, I want to extract the keywords Only form the below Script's output: <?php $keywords = file_get_contents('http://suggestqueries.google.com/complete/search?hl=en&gl=us&ds=pr&client=products&hjson=t&jsonp=ac_hr&q=paintball&cp=2'); //$keywords = json_decode($keywords); print_r($keywords); ?> Output is: ac_hr(["paintball",[["paintballs","","0"],["paintball sniper","","1"],["paintball mask","","2"],["paintball vest","","3"],["paintball pants","","4"],["paintball bunkers","","5"],["paintball markers","","6"],["paintball chronograph","","7"],["paintball bow","","8"],["paintball helmets","","9"]],"","","","","",{}]) How to extract the keywords Only in an Array?? Cheers Natasha T I am trying to make a form search through user input, and link it up with existing data in the database. so if in the text field, the person puts " flowers, red roses, white roses, daisies, sunflowers, cars" then they press "submit" the code then runs sql to search the database with matching terms. So that if the terms in the database field row are things->DBentry1->flowers, trucks, cars, red roses, things->DBentry2->dogs, cats, flowers it will echo out " 2 entries have matches "entry 1 has flowers, cars and red roses" "entry 2 has flowers" I want the results to be in order of number of matches returned for that database entry. it will skip "trucks because trucks was not entered and so did not match., Basically I want the search form to let the user put the terms in separated by a comma and a space or without a space, and then php and mysql find the matching terms, then echo out the results in matching order from most to least. I know that is a lot to ask of you all, but I would appreciate any help. Thanks in advance. I have a php line like: echo "<p><b>Tags: </b>" . $row['tags'] . "</p>";
it looks like this on web page: how do i add hyperlink to each keyword like: Tags: <a href='category/keyword1'>keyword1</a>, <a href='category/keyword2'>keyword2</a>, <a href='category/keyword3'>keyword3</a>,...
Here's a neat little script that you simply use by calling yourscript.php?microsoft (where microsoft is any keyword you want) and it returns 100 related keywords. It's pretty raw in it's form. I didn't write it. Purely for learning, I'm trying to figure out how to 1) issue a line break between each item in the elements of the arry? 2) return only the keywords and not the associated array info. Currently, it returns results like: Array ( => microsoft [1] => microsoft security essentials [2] => microsoft office [3] => microsoft templates [4] => microsoft updates [5] => microsoft silverlight [6] => microsoft word [7] => microsoft money [8] => microsoft office 2010 [9] => microsoft clip art [10] => microsoft [11] => microsoft security essentials [12] => microsoft office [13] => microsoft templates [14] => microsoft updates [15] => microsoft silverlight [16] => microsoft word [17] => microsoft money [18] => microsoft office 2010 [19] => microsoft clip art [20] => microsoft security essentials [21] => microsoft security essentials review [22] => microsoft security essentials alert [23] => microsoft security essentials update [24] => microsoft security essentials 2.0 I'm wanting to know how to make it return results like... microsoft microsoft security essential microsoft office microsoft templates etc.... Code: [Select] <?php function text_between($start,$end,$string) { if ($start != '') {$temp = explode($start,$string,2);} else {$temp = array('',$string);} $temp = explode($end,$temp[1],2); return $temp[0]; } function gsscrape($keyword) { $keyword=str_replace(" ","+",$keyword); global $kw; $data=file_get_contents('http://clients1.google.com/complete/search?hl=en&q='.$keyword); $data=explode('[',$data,3); $data=explode('],[',$data[2]); foreach($data as $temp) { $kw[]= text_between('"','"',$temp); } } #simple to use, just use yourscriptname.php?keywords if ($_SERVER['QUERY_STRING']!='') { gsscrape($_SERVER['QUERY_STRING']); foreach ($kw as $keyword) { gsscrape($keyword); } #all results are in array $kw... print_r($kw); } ?> hi there - first attempt at programming in PHP so please bear with my novice attempts (not much programming experience in any languege really) i am building a site which hosts mp3s. I have MySQL database with one of the fields contating descriptive keywords for the tracks (such as slow, chilled, intense etc) i have created an html page with search form that send data to php file which runs a query of the keywords field - and all works fine now i want that in addition to the search form (with an input text box for the search criteria and the submit button) i will have a 'cloud' of key words - clickable links - that will send the data to the PHP query file (clicking on slow will search for tracks described with 'slow' and so on) - any ideas how do send data by clicking on a link? my html form is: Code: [Select] <body bgcolor="white"> <form action="test3.php" target="main" method="post"> <input type="text" name="searchkeywords" size=100><br> <input type="submit" value="Search"> <input name="searchkeywords" value="slow" type="submit"> </form> <DIV align="center" style="left : 240px; position : absolute; top : 100px;"><iframe src ="test3.php" width="1000" height="800" name="main" frameborder="2" scrolling="no"> <p>Your browser does not support iframes.</p> </iframe></DIV> </body> my php query file is: Code: [Select] <?php $con = mysql_connect("localhost","root","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); $result = mysql_query("SELECT * FROM music WHERE keywords LIKE '%$_POST[searchkeywords]%'"); $txt1='<A HREF="/audioplayer-standalone/'; $txt2='" ><IMG src="images/misc_23.png" width="32" height="32" align="left" border="0"></A>'; $txt3='<script language="JavaScript" src="/audioplayer-standalone/audio-player.js"></script><object type="application/x-shockwave-flash" data="/audioplayer-standalone/player.swf" id="audioplayer'; $txt4='" height="24" width="290"><param name="movie" value="/audioplayer-standalone/player.swf"><param name="FlashVars" value="playerID=audioplayer'; $txt5='&soundFile=/audioplayer-standalone/'; $txt6='"><param name="quality" value="high"><param name="menu" value="false"><param name="wmode" value="transparent"> </object>'; echo "<table border='1'> <tr> <th width='220' align='left'>Track Name</th> <th width='220' align='left'>Artist</th> <th width='220' align='left'>Description</th> <th></th> <th></th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['track'] . "</td>"; echo "<td>" . $row['artist'] . "</td>"; echo "<td>" . $row['description'] . "</td>"; echo "<td>" . $txt1.$row['filename'].$txt2 . "</td>"; echo "<td>" . $txt3.$row['id'].$txt4.$row['id'].$txt5.$row['filename'].$txt6 ."</td>"; echo "</tr>"; } echo "</table>"; // some code mysql_close($con); ?> I'm looking to know the best way to process a search query that has multiple words in the search: Code: [Select] elseif(isset($_GET['search'])){ $search=$_GET['search']; $keyword=explode(" ",$search); //database query } Should I do a while loop query the database for each keyword? Hello i am making a page that shows the description title etc of a page and shows some other info's.... I Came across the script from this page and i was wondering how well is it wroted Dos anyone know a shorter script that dos that functions? Ok, first let me tell you what I want to do. Google sends me traffic from many keywords, but I want to track what keyword does best for me as sales and so. The Analytics is good but I can't send the data to outside sites. So I figured this out : from the $_SERVER['HTTP_REFERER'] I can get the "q" value from the _GET and pass it on to track it... now I'm kind of stuck and I know it's easy but can't seem to find the function. This is what I have so far: /* Code to try and store the keyword that was used to find and land on my site. */ $exurl = 'http://www.google.ca/url?sa=t&source=web&cd=1&ved=0CBYQFjAA&rct=j&q=mykeyword&ei=pJ2STMy8MsP-8AaqvuznBQ'; //set a demo refferer url that would usually be $exurl = $_SERVER['HTTP_REFERER'] $refurl = parse_url($exurl, PHP_URL_QUERY); // remove all before and including the "?" echo $refurl; // echo "sa=t&source=web&cd=1&ved=0CBYQFjAA&rct=j&q=mykeyword&ei=pJ2STMy8MsP-8AaqvuznBQ" Ok, so I managed to get the important part out of the google URL, now how do I split this into an array that I can then use. For instance somefunction($refurl, $newarray); and then I could say | echo $newarray['q']; | and it would echo "mykeyword" Of course If there is a space in the keywords I should use the urldecode() function to avoid the % char... Let me know if you know of any way to get this done. how should i approach this with preg_match? i have a text: "big red apple" now i want the script to create a href for each keyword apple and link to http://apple.com examples appreciated Hi, I'm trying to get a number of different keywords from many table fields, and i want to count them according to the occurrence of each keyword, so it should be like (keyword1 occurred 10 times for example ). the problem is when i use count in for loop: Code: [Select] $tags = explode("|", $row[0]); $i=1; $count = 0; for($i; $i<count($tags); $i++){ print "$count {$tags[$i]}<br />"; $count++; } it counts the occurrence of key words in each field separately from the rest (i.e. Code: [Select] 0 day 1 night 0sun 1 moon 0 clouds 1 rain ) 2 keywords in each field (some other fields got more). I want the count to be more like: Code: [Select] 1 day 2 night 3 sun 4 moon 5 clouds 6 rain thanks //get the search variable from the FORM$function_keywords = mysql_real_escape_string($_POST['function_keywords']);//trim whitespace from the stored variable$trimmed = trim($function_keywords);//separate key-phrases into keywords$trimmed_keywords = explode(" ",$trimmed);// Build SQL Query for each keyword enteredforeach ($trimmed_keywords as $trimm){// MySQL "MATCH" is used for full-text searching.//this code is ebv weird , should check out soon!$query = "SELECT * , MATCH (function_description) AGAINST ('".$trimm."') AS score FROM table_name WHERE MATCH (function_description) AGAINST ('+".$trimm."') ORDER BY score DESC "; // Execute the query to get number of rows that contain search kewords $results=mysql_query ($query,$connection); $row=""; $row =$row . mysql_fetch_array($results, MYSQL_BOTH);} $row_num=mysql_num_rows ($row); if($row_num < 1){ redirect("welcome.php?search=fail"); } else if ($row_num > 1){ ?> <html> <head> <title>Search results</title> </head> <body> <?php foreach($row as $row_result){ echo "function name : {$row_result['function_name']} --- function Description : {$row_result['function_description']}<br/><br/>"; }?> </body> </html>() IS there an error on the SQL syntax ? or its about ? : Code: [Select] $results=mysql_query ($query,$connection); $row=""; $row =$row . mysql_fetch_array($results, MYSQL_BOTH); } $row_num=mysql_num_rows ($row); I am developing a intranet forum in Php and MySQL and I am using ajax to display searched results on the same page but right now I am using query LIKE text% to search in database which is slower. but I want to make it fast search engin which can parse *,+ and show result. Since I am using ajax i am not able to use free search engin,so if possible pls provide a complete solution hi i am trying to make a payroll calculator script that takes employee info, calculates pay, displays submitted info in a table, stores info in an array, and updates the array when new info is submitted. i have most of these accomplished, i am having trouble with the "store into an array, and update the array when new info is submitted" parts of the project. i am still not very fluent in php so there may be easier ways to achieve what i have so far. any pointers would be a great help, this part has got me stumped. NOTE - Please read the information first as it contains important information to understand the problem. Rules → • There are 9 Columns(C1,C2,C3,C4,C5,C6,C7,C8,C9) [ Max columns will be 9] • The number of Rows can vary from 3,6,9,12,15,18 (Max). In this case Number of Rows shall be 12 Number of Rows = No of Tickets (Max Allowed 6) x Rows Per Ticket (Max Allowed 3). Thus, Max Rows can be 18 • Each Row is required to have 4 Blank Spaces and 5 Filled with Numbers • All numbers available in the Column Array have to be utilized • This configuration of an shall create a matrix of 9 Columns & 12 Rows (3 x 4 Tickets), which is 108 MATRIX BLOCKS where only a maximum of 60 numbers can be filled out of 108 available blocksrandomly with the above conditions being met 100%. • The numbers in column must be arranged / sorted in ASCENDING ORDER (For coding logic purpose, as soon as the number is assigned to the new MATRIX MAP use array_shift() or unset() the number so as to avoid repetition Example - Row 1 and Column 1 shall generate a MATRIX BLOCK - R1C1 Row 3 and Column 7 shall generate a MATRIX BLOCK - R3C7 Matrix Block can also be termed as Matrix Cell for your ease (if needed) MASTER SET OF ARRAY WITH NUMBERS array( "C1"=> array( 1, 2, 3, 5, 6, 7, 9 ), //7 Numbers "C2"=> array( 13, 14, 15, 17, 18, 19 ), //6 Numbers "C3"=> array( 21, 22, 23, 24, 25, 26, 30 ), //7 Numbers "C4"=> array( 31, 33, 34, 36, 37, 38, 39 ), //7 Numbers "C5"=> array( 41, 42, 46, 47, 48, 49, 50 ), //7 Numbers "C6"=> array( 51, 52, 53, 54, 55, 57, 58 ), //7 Numbers "C7"=> array( 61, 62, 64, 65, 69, 70 ), //6 Numbers "C8"=> array( 71, 74, 75, 76, 77, 78 ), //6 Numbers "C9"=> array( 82, 83, 85, 87, 88, 89, 90 ) //7 Numbers ); The above array has 60 Numbers to be filled out of 108 MATRIX BLOCK / CELL which meets the condition that for a FULL BLOCK containing 4 MINI BLOCKS WITH 3 ROWS (max. allowed) EACH I have been able to generate this without any issue meeting all the conditions of the Columns My Allocation Matrix Array will look like array( "R1"=> array( "C1"=> true, // Means that MATRIX BLOCK R1C1 will be NOT EMPTY "C2"=> false, // Means that MATRIX BLOCK R1C2 will be EMPTY "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> false ), "R2"=> array( "C1"=> false, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> true, "C8"=> true, "C9"=> false ), "R3"=> array( "C1"=> true, "C2"=> true, "C3"=> true, "C4"=> true, "C5"=> false, "C6"=> false, "C7"=> false, "C8"=> false, "C9"=> true ), "R4"=> array( "C1"=> true, "C2"=> true, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> false ), "R5"=> array( "C1"=> false, "C2"=> false, "C3"=> false, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> true, "C8"=> true, "C9"=> true ), "R6"=> array( "C1"=> true, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ), "R7"=> array( "C1"=> false, "C2"=> false, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> true ), "R8"=> array( "C1"=> true, "C2"=> false, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> true ), "R9"=> array( "C1"=> true, "C2"=> false, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ), "R10"=> array( "C1"=> false, "C2"=> true, "C3"=> true, "C4"=> true, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> false, "C9"=> false ), "R11"=> array( "C1"=> false, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> true, "C9"=> false ), "R12"=> array( "C1"=> true, "C2"=> false, "C3"=> true, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ) ); In the above array R stands for Row, C for Column, TRUE/FALSE (Boolean) means that if TRUE a Number can be filled in the resulting MATRIX BLOCK / CELL ( Row[Number]Column[Number] ) else if FALSE the MATRIX BLOCK / CELL shall be EMPTY The result for the above shall be
PROBLEM : I am unable to understand what should possibly be the logic & loop used here for creating a MATRIX ALLOCATION MAP as shown above I have tried while, foreach & for but unable determine the perfect combination which would meet the conditions. (Tried all of the above with Nested Loops also) Edited May 1, 2020 by AlphaMikeTags |