Jump to content

Search the Community

Showing results for tags 'multidimensional'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 6 results

  1. Hi all, I would like to ask you if somebody could have a better idea to build this function. The current one is working, but I feel this built a bit in an amateur manner. Feel free to add your ideas so we can learn more about PHP and how to deal with arrays. I have an array: $arrayVideoSpecs = Array( Array( 'aspect' => '4:3', 'density' => '442368', 'resolution' => '768x576' ), Array( 'aspect' => '4:3', 'density' => '307200', 'resolution' => '640x480' ), Array( 'aspect' => '16:9', 'density' => '2073600', 'resolution' => '1920x1080' ), Array( 'aspect' => '16:9', 'density' => '121600', 'resolution' => '1280x720' ) ); and I want an array as output grouped by video aspect ratio where the key is the pixel density and the value is the video resolution, namely like that for aspect ratio 16:9 ... Array ( [2073600] => 1920x1080 [121600] => 1280x720 ) Then I coded this function which is working but seems amateur ... function groupAndExtractByAspect($array, $groupBy, $aspect, $density, $resolution) { $groupByAspect = Array(); foreach ($array as $value) { $groupByAspect[$value[$aspect]][] = Array($value[$density], $value[$resolution]); } $arrayClean = Array(); foreach ($groupByAspect as $key => $value) { if ($key == $groupBy) { $arrayClean[$key] = $value; } } foreach ($arrayClean as $aspectGroup) { $arrayOutput = Array(); for ($i = 0; $i <= count($aspectGroup); $i++) { $densityIsValid = false; $resolutionIsValid = false; if (!empty($arrayClean[$groupBy][$i][0])) { $density = $arrayClean[$groupBy][$i][0]; $densityIsValid = true; } if (!empty($arrayClean[$groupBy][$i][1])) { $resolution = $arrayClean[$groupBy][$i][1]; $resolutionIsValid = true; } if (($densityIsValid === true) && ($resolutionIsValid === true)) { $arrayOutput[$density] = $resolution; } } } return $arrayOutput; } The usage is as follow ... $showArray = groupAndExtractByAspect($arrayVideoSpecs, '16:9', 'aspect', 'density', 'resolution'); echo '<pre>'; print_r($showArray); echo '</pre>'; Thank you very much for your ideas! Mapg
  2. I have a multidimensional array, lets say it's consisting of arrays for groups of balls and then with the key as the number of the ball and then subkeys for color and size, something like what can be seen below (slightly simplified). If I want to select as many balls as possible, based on their size, but there has to be 1) at least one ball from each group and 2) the number of balls from each group multiplied with each other can't be more than lets say 20, and also 3) one of the groups has to have only one single ball selected (to maximize the number of balls selected in total). I know the basics about arrays and foreach loops and so on but how would I go about checking for these above mentioned limitations? Array( [Group1] => Array ( [1] => Array ( [color] => 'blue' [size] => 1.25 ) [2] => Array ( [color] => 'red' [size] => 1.59 ) [3] => Array ( [color] => 'red' [size] => 1.20 ) [4] => Array ( [color] => 'green' [size] => 1.91 ) [5] => Array ( [color] => 'blue' [size] => 1.73 ) ) [Group2] => Array ( [1] => Array ( [color] => 'red' [size] => 1.84 ) [2] => Array ( [color] => 'red' [size] => 1.21 ) [3] => Array ( [color] => 'green' [size] => 1.17 ) [4] => Array ( [color] => 'green' [size] => 1.46 ) [5] => Array ( [color] => 'blue' [size] => 1.70 ) ) [Group3] => Array ( [1] => Array ( [color] => 'red' [size] => 1.04 ) [2] => Array ( [color] => 'yellow' [size] => 1.99 ) [3] => Array ( [color] => 'orange' [size] => 1.07 ) [4] => Array ( [color] => 'blue' [size] => 1.12 ) [5] => Array ( [color] => 'blue' [size] => 1.18 ) ) [Group4] => Array ( [1] => Array ( [color] => 'blue' [size] => 1.66 ) [2] => Array ( [color] => 'blue' [size] => 1.24 ) [3] => Array ( [color] => 'blue' [size] => 1.45 ) [4] => Array ( [color] => 'blue' [size] => 1.42 ) [5] => Array ( [color] => 'red' [size] => 1.38 ) ))
  3. I am trying to read a large number of products, from a CSV file. I am attempting to parse each line and produce item lists, each with a Make, Model and set of OEM numbers. Multiple models use the same set of OEM values. Here is a sample screenshot of my product spreadsheet. - http://prntscr.com/3aorwh Here is my code below. Underneath will be my CSV contents (only a sample) error_reporting(0); $file = fopen("new.csv","r"); $makeArray = array(); $make = ''; $model = 0; $specificModel = ''; while(! feof($file)) { $lineVal = fgetcsv($file, 0, '@'); // Adds in 'Make' to initial makeArray array if ( isset($lineVal[0]) && empty( $lineVal[1] ) && empty( $lineVal[2] ) ) { $make = $lineVal[0]; $makeArray[$make] = array(); } // Gets Model lists if ($lineVal[1] !== '') { $model++; $makeArray[$make][$model] = array(); $specificModel = explode(",", $lineVal[1]); foreach($specificModel as $t) { $makeArray[$make][$model][$t] = array(); } } $OEMs = explode(',', $lineVal[2]); foreach($makeArray[$make][$model] as $specific) { if ($specific !== '') { // This loop adds in the variables foreach($OEMs as $oem){ $makeArray[$make][$model][$t][$oem] = array(); } } } } // Echo results echo '<pre>'; var_dump($makeArray) . '<br />'; echo '</pre>'; fclose($file); Here is the CSV content: Brother@@ Brother TN12K Compatible Black Toner Cartridge@HL-4200 Series@TN12BK Brother TN12C Compatible Cyan Toner Cartridge@@TN12C Brother TN12M Compatible Magenta Toner Cartridge@@TN12M Brother TN12Y Compatible Yellow Toner Cartridge@@TN12Y Brother TN04K Compatible Black Toner Cartridge, For HL-2700,@HL-2700CN,MFC-9420CN@TN04BK Brother TN04C Compatible Cyan Toner Cartridge, For HL-2700,@@TN04C Brother TN04M Compatible Magenta Toner Cartridge@@TN04M Brother TN04Y Compatible Yellow Toner Cartridge@@TN04Y When I output my code, the following structure occurs. Please note at this point, the OEM values are grouped, and each model within the dark borders on the left, has to have ALL of the values on the right side within these borders. Output array(1) { ["Brother"]=> array(2) { [1]=> array(1) { ["HL-4200 Series"]=> array(4) { ["TN12BK"]=> array(0) { } ["TN12C"]=> array(0) { } ["TN12M"]=> array(0) { } ["TN12Y"]=> array(0) { } } } [2]=> array(2) { ["HL-2700CN"]=> array(0) { } [" MFC-9420CN"]=> array(4) { ["TN04BK"]=> array(0) { } ["TN04C"]=> array(0) { } ["TN04M"]=> array(0) { } ["TN04Y "]=> array(0) { } } } } } Any takers as to why HL-2700CN and MFC-9420CN (or any sections like this) do not ALL get assigned the respective grouped OEMs? Additional information: The format of the end result needs to look like: Brother HL-4200 Series TN12BK TN12C TN12M TN12Y HL-2700CN TN04BK TN04C TN04M TN04Y MFC-9420CN TN04BK TN04C TN04M TN04Y Thanks
  4. this is a code of a shopping cart i'm trying to make. the cart displays the products with: name, size, price, quantity and total. When checked out it saves on Mysql DB. So it saves like this: user_1 | pants | XL | 10 $ | 1 | 10 $ | user_1 | t-shirt | L | 5 $ | 2 | 10 $ | user_2 | sock s | 8 | 7 $ | 5 | 35 $ | it's creating new row for each product for the same user. But what i need is this: user_1 | pants, t-shirt | XL, L | 10, 5 $ | 1, 2 | 20 $ | user_2 | socks | 8 | 7 $ | 5 | 35 $ | user_3 | t-shirt, hat | M, S | 5, 10 $ | 1, 1 | 15 $ | for the same user he implodes the data in the column of the same row. code: $products_array[$i] = array("user" => $user, "product" => $name_product, "size" => $size, "price" => $price, "quantity" => $each_item['quantity'], "total" => $cartTotal); if (isset($_SESSION["cart_array"]) && count($products_array) > 0 && isset($_POST['addOrder'])) { foreach ($products_array as $product) { $user = $_SESSION["user"]; $name_product = $product['name_product']; $size = $product['size']; $price = $product['price']; $quantity = $product['quantity']; $cartTotal = $product['total']; $result = mysqli_query($dbc,"INSERT INTO shop (user, product, size, price, quantity, total, date) VALUES('$user','$name_product','$size','$price','$quantity','$cartTotal',now())"); header("location: shop_cart.php"); } } So i been googling arround, and found that what i need is a implode function. But my problem is where and how to set it right. I have tried some code already but it doesnt work. I dont want to flood the DB Table with multiple rows of the same purchase. Any other suggestions on what to do to achieve my goal is accepted. Appreciate your help. Thank you.
  5. Hey guys, I am working for the first time without a database and MySQL while using PHP. anyway i am working on a real estate page and i am having issues on the "areas we cover", and this section would allow a user to view the neighborhoods or locations that the real estate agent has listings or does showings. i created a multidimensional array with the data i need. <?php $cities = array('pasadena' => array( "name" => "Pasadena", "picture" => "pasadena.png", "link" => "https://maps.google.com/maps?q=pasadena+ca&ie=UTF-8&ei=21uRUqGUKY3VoATvsILwDA&ved=0CAgQ_AUoAg", "value" => "1", "details" => "This is where the details will go", 'data' => '<div id="tGraphs" style="border: 1px solid #ccc; padding: 5px 0px 5px 0px; width:300px; text-align:center;"><script language="javascript" type="text/javascript" src="http://synd.trulia.com/tools/chart/style_default300/type_average_listing_price/CA/Pasadena/"></script></div>', 'second_image' => '<img src="altadena_home.jpg" height="195" width="200">', 'trulia' => '<style type="text/css"> .module {overflow:visible;}/*For typepad*/ #tMinistats { position:relative; width:180px; } #tMinistats .tMinistatsS { text-align:center; position:relative;bottom:0;margin-bottom:70px;width:95%; z-index:100;color:#b6d46f;font-family:Arial;font-size:11px; } #tMinistats .tMinistatsS a { color:#06c; }</style><div id="tMinistats" style="background-color:#ffffff;"> <script type="text/javascript" language="javascript" src="http://synd.trulia.com/tools/ministats/style_default180/CA/Pasadena/"></script> </div>', 'second_image' => '<div style="position:relative; top:-30px; left:10px; border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena1.jpg" alt="Altadena Home" height="250" width="220"></div>', 'third_image' => '<div style="position:relative; top:-282px; left:260px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena2.jpg" alt="Altadena Home" height="250" width="220"></div>', 'fourth_image' => '<div style="position:relative; top:-535px; left:510px;margin-bottom: -500px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena3.jpg" alt="Altadena Home" height="250" width="220"></div>' ), 'glendale' => array( "name" => "Glendale", "picture" => "glendale.png", "link" => "https://maps.google.com/maps?q=glendale+ca&ie=UTF-8&ei=wFuRUvSBFNLroASkvYKgDw&ved=0CAgQ_AUoAg", "value" => "2", "details" => "This is where the details will go", 'data' => '<div id="tGraphs" style="border: 1px solid #ccc; padding: 5px 0px 5px 0px; width:300px; text-align:center;"><script language="javascript" type="text/javascript" src="http://synd.trulia.com/tools/chart/style_default300/type_average_listing_price/CA/Glendale/"></script></div>', 'second_image' => '<img src="altadena_home.jpg" height="195" width="200">', 'trulia' => '<style type="text/css"> .module {overflow:visible;}/*For typepad*/ #tMinistats { position:relative; width:180px; } #tMinistats .tMinistatsS { text-align:center; position:relative;bottom:0;margin-bottom:70px;width:95%; z-index:100;color:#b6d46f;font-family:Arial;font-size:11px; } #tMinistats .tMinistatsS a { color:#06c; }</style><div id="tMinistats" style="background-color:#ffffff;"> <script type="text/javascript" language="javascript" src="http://synd.trulia.com/tools/ministats/style_default180/CA/Glendale/"></script> </div>', 'second_image' => '<div style="position:relative; top:-30px; left:10px; border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena1.jpg" alt="Altadena Home" height="250" width="220"></div>', 'third_image' => '<div style="position:relative; top:-282px; left:260px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena2.jpg" alt="Altadena Home" height="250" width="220"></div>', 'fourth_image' => '<div style="position:relative; top:-535px; left:510px;margin-bottom: -500px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena3.jpg" alt="Altadena Home" height="250" width="220"></div>' ), 'eagle rock' => array( "name" => "Eagle Rock", "picture" => "eagle.png", "link" => "https://maps.google.com/maps?q=eagle+rock+maps&ie=UTF-8&ei=cluRUtLDB9LuoASw8YDoDw&ved=0CAgQ_AUoAg", "value" => "3", "details" => "This is where the details will go", 'data' => '<div id="tGraphs" style="border: 1px solid #ccc; padding: 5px 0px 5px 0px; width:300px; text-align:center;"><script language="javascript" type="text/javascript" src="http://synd.trulia.com/tools/chart/style_default300/type_average_listing_price/CA/Eagle_Rock/"></script></div>', 'second_image' => '<img src="altadena_home.jpg" height="195" width="200">', 'trulia' => '<style type="text/css"> .module {overflow:visible;}/*For typepad*/ #tMinistats { position:relative; width:180px; } #tMinistats .tMinistatsS { text-align:center; position:relative;bottom:0;margin-bottom:70px;width:95%; z-index:100;color:#b6d46f;font-family:Arial;font-size:11px; } #tMinistats .tMinistatsS a { color:#06c; }</style><div id="tMinistats" style="background-color:#ffffff;"> <script type="text/javascript" language="javascript" src="http://synd.trulia.com/tools/ministats/style_default180/CA/Eagle_Rock/"></script> </div>', 'second_image' => '<div style="position:relative; top:-30px; left:10px; border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena1.jpg" alt="Altadena Home" height="250" width="220"></div>', 'third_image' => '<div style="position:relative; top:-282px; left:260px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena2.jpg" alt="Altadena Home" height="250" width="220"></div>', 'fourth_image' => '<div style="position:relative; top:-535px; left:510px;margin-bottom: -500px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena3.jpg" alt="Altadena Home" height="250" width="220"></div>' ), 'silverlake' => array( "name" => "Silverlake", "picture" => "silverlake.png", "link" => "https://maps.google.com/maps?q=Silverlake+Ca&ie=UTF-8&ei=VFuRUrOLJMXwoASt74CQDQ&ved=0CAoQ_AUoAg", "value" => "4", "details" => "This is where the details will go", 'data' => '<div id="tGraphs" style="border: 1px solid #ccc; padding: 5px 0px 5px 0px; width:300px; text-align:center;"><script language="javascript" type="text/javascript" src="http://synd.trulia.com/tools/chart/style_default300/type_average_listing_price/CA/Silver_Lake/"></script></div>', 'second_image' => '<img src="altadena_home.jpg" height="195" width="200">', 'trulia' => '<style type="text/css"> .module {overflow:visible;}/*For typepad*/ #tMinistats { position:relative; width:180px; } #tMinistats .tMinistatsS { text-align:center; position:absolute;bottom:0;margin-bottom:70px;width:95%; z-index:100;color:#b6d46f;font-family:Arial;font-size:11px; } #tMinistats .tMinistatsS a { color:#06c; }</style><div id="tMinistats" style="background-color:#ffffff;"> <script type="text/javascript" language="javascript" src="http://synd.trulia.com/tools/ministats/style_default180/90026"></script></div>', 'second_image' => '<div style="position:relative; top:-30px; left:10px; border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena1.jpg" alt="Altadena Home" height="250" width="220"></div>', 'third_image' => '<div style="position:relative; top:-282px; left:260px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena2.jpg" alt="Altadena Home" height="250" width="220"></div>', 'fourth_image' => '<div style="position:relative; top:-535px; left:510px;margin-bottom: -500px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena3.jpg" alt="Altadena Home" height="250" width="220"></div>' ), 'atwater' => array( "name" => "Atwater Village", "picture" => "atwater_village.png", "link" => "https://maps.google.com/maps?q=atwater+village&ie=UTF-8&hq=&hnear=0x80c2c0e875cbce3b:0x99ebb9fd977ae16f,Atwater+Village,+Los+Angeles,+CA&gl=us&ei=kVGRUrzgHoTloAT_u4HADg&ved=0CKYBELYD", "value" => "5", "details" => "This is where the details will go", 'data' => '', 'trulia' => '<style type="text/css"> .module {overflow:visible;}/*For typepad*/ #tMinistats { position:relative; width:180px; } #tMinistats .tMinistatsS { text-align:center; position:absolute;bottom:0;margin-bottom:70px;width:95%; z-index:100;color:#b6d46f;font-family:Arial;font-size:11px; } #tMinistats .tMinistatsS a { color:#06c; }</style><div id="tMinistats" style="background-color:#ffffff;"> <script type="text/javascript" language="javascript" src="http://synd.trulia.com/tools/ministats/style_default180/90026"></script></div>', 'second_image' => '<div style="position:relative; top:-30px; left:10px; border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena1.jpg" alt="Altadena Home" height="250" width="220"></div>', 'third_image' => '<div style="position:relative; top:-282px; left:260px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena2.jpg" alt="Altadena Home" height="250" width="220"></div>', 'fourth_image' => '<div style="position:relative; top:-535px; left:510px;margin-bottom: -500px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena3.jpg" alt="Altadena Home" height="250" width="220"></div>' ), 'palmdale' => array( "name" => "Palmdale", "picture" => "palmdale.png", "link" => "https://maps.google.com/maps?q=Palmdale+Ca&ie=UTF-8&ei=G1qRUti1NonuoASHsIK4Cw&ved=0CAoQ_AUoAg", "value" => "6", "details" => "This is where the details will go", 'data' => '<div id="tGraphs" style="border: 1px solid #ccc; padding: 5px 0px 5px 0px; width:300px; text-align:center;"><script language="javascript" type="text/javascript" src="http://synd.trulia.com/tools/chart/style_default300/type_average_listing_price/CA/Palmdale/"></script></div>', 'second_image' => '<img src="altadena_home.jpg" height="195" width="200">', 'trulia' => '<style type="text/css"> .module {overflow:visible;}/*For typepad*/ #tMinistats { position:relative; width:180px; } #tMinistats .tMinistatsS { text-align:center; position:relative;bottom:0;margin-bottom:70px;width:95%; z-index:100;color:#b6d46f;font-family:Arial;font-size:11px; } #tMinistats .tMinistatsS a { color:#06c; }</style><div id="tMinistats" style="background-color:#ffffff;"> <script type="text/javascript" language="javascript" src="http://synd.trulia.com/tools/ministats/style_default180/CA/Palmdale/"></script> </div>', 'second_image' => '<div style="position:relative; top:-30px; left:10px; border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena1.jpg" alt="Altadena Home" height="250" width="220"></div>', 'third_image' => '<div style="position:relative; top:-282px; left:260px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena2.jpg" alt="Altadena Home" height="250" width="220"></div>', 'fourth_image' => '<div style="position:relative; top:-535px; left:510px;margin-bottom: -500px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena3.jpg" alt="Altadena Home" height="250" width="220"></div>' ), 'lancaster' => array( "name" => "Lancaster", "picture" => "lancaster.png", "link" => "https://maps.google.com/maps?q=Lancaster+CA&ie=UTF-8&ei=elqRUqT_D8HroASK-oGwDw&ved=0CAgQ_AUoAg", "value" => "7", "details" => "This is where the details will go", 'data' => '<div id="tGraphs" style="border: 1px solid #ccc; padding: 5px 0px 5px 0px; width:300px; text-align:center;"><script language="javascript" type="text/javascript" src="http://synd.trulia.com/tools/chart/style_default300/type_average_listing_price/CA/Lancaster/"></script></div>', 'second_image' => '<img src="altadena_home.jpg" height="195" width="200">', 'trulia' => '<style type="text/css"> .module {overflow:visible;}/*For typepad*/ #tMinistats { position:relative; width:180px; } #tMinistats .tMinistatsS { text-align:center; position:relative;bottom:0;margin-bottom:70px;width:95%; z-index:100;color:#b6d46f;font-family:Arial;font-size:11px; } #tMinistats .tMinistatsS a { color:#06c; }</style><div id="tMinistats" style="background-color:#ffffff;"> <script type="text/javascript" language="javascript" src="http://synd.trulia.com/tools/ministats/style_default180/CA/Lancaster/"></script> </div>', 'second_image' => '<div style="position:relative; top:-30px; left:10px; border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena1.jpg" alt="Altadena Home" height="250" width="220"></div>', 'third_image' => '<div style="position:relative; top:-282px; left:260px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena2.jpg" alt="Altadena Home" height="250" width="220"></div>', 'fourth_image' => '<div style="position:relative; top:-535px; left:510px;margin-bottom: -500px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena3.jpg" alt="Altadena Home" height="250" width="220"></div>' ), 'burbank' => array( "name" => "Burbank", "picture" => "burbank.png", "link" => "https://maps.google.com/maps?q=Burbank+Ca&ie=UTF-8&ei=qlmRUuKXF5HroATysoJI&ved=0CAoQ_AUoAg", "value" => "8", "details" => "This is where the details will go", 'data' => '<div id="tGraphs" style="border: 1px solid #ccc; padding: 5px 0px 5px 0px; width:300px; text-align:center;"><script language="javascript" type="text/javascript" src="http://synd.trulia.com/tools/chart/style_default300/type_average_listing_price/CA/Burbank/"></script></div>', 'second_image' => '<img src="altadena_home.jpg" height="195" width="200">', 'trulia' => '<style type="text/css"> .module {overflow:visible;}/*For typepad*/ #tMinistats { position:relative; width:180px; } #tMinistats .tMinistatsS { text-align:center; position:relative;bottom:0;margin-bottom:70px;width:95%; z-index:100;color:#b6d46f;font-family:Arial;font-size:11px; } #tMinistats .tMinistatsS a { color:#06c; }</style><div id="tMinistats" style="background-color:#ffffff;"> <script type="text/javascript" language="javascript" src="http://synd.trulia.com/tools/ministats/style_default180/CA/Burbank/"></script> </div>', 'second_image' => '<div style="position:relative; top:-30px; left:10px; border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena1.jpg" alt="Altadena Home" height="250" width="220"></div>', 'third_image' => '<div style="position:relative; top:-282px; left:260px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena2.jpg" alt="Altadena Home" height="250" width="220"></div>', 'fourth_image' => '<div style="position:relative; top:-535px; left:510px;margin-bottom: -500px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena3.jpg" alt="Altadena Home" height="250" width="220"></div>' ), 'altadena' => array( "name" => "Altadena", "picture" => "altadena.png", "link" => "https://maps.google.com/maps?q=altadena+ca&ie=UTF-8&ei=01iRUrW1I8zloATwn4KgBA&ved=0CAoQ_AUoAg", "value" => "9", "details" => "This is where the details will go", 'data' => '<div id="tGraphs" style="border: 1px solid #ccc; padding: 5px 0px 5px 0px; width:300px; text-align:center;"><script language="javascript" type="text/javascript" src="http://synd.trulia.com/tools/chart/style_default300/type_average_listing_price/CA/Altadena/"></script></div>', 'second_image' => '<img src="altadena_home.jpg" height="195" width="200">', 'trulia' => '<style type="text/css"> .module {overflow:visible;}/*For typepad*/ #tMinistats { position:relative; width:180px; } #tMinistats .tMinistatsS { text-align:center; position:relative;bottom:0;margin-bottom:70px;width:95%; z-index:100;color:#b6d46f;font-family:Arial;font-size:11px; } #tMinistats .tMinistatsS a { color:#06c; }</style><div id="tMinistats" style="background-color:#ffffff;"> <script type="text/javascript" language="javascript" src="http://synd.trulia.com/tools/ministats/style_default180/CA/Altadena/"></script> </div>', 'second_image' => '<div style="position:relative; top:-30px; left:10px; border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena1.jpg" alt="Altadena Home" height="250" width="220"></div>', 'third_image' => '<div style="position:relative; top:-282px; left:260px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena2.jpg" alt="Altadena Home" height="250" width="220"></div>', 'fourth_image' => '<div style="position:relative; top:-535px; left:510px;margin-bottom: -500px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena3.jpg" alt="Altadena Home" height="250" width="220"></div>' ), 'z_all' => array( "name" => "Sorry! Didn't find your city? We can show more.", "picture" => "all.png", "link" => "contact_us.php", "value" => "10", "details" => "This is where the details will go", 'data' => '<div id="tGraphs" style="border: 1px solid #ccc; padding: 5px 0px 5px 0px; width:300px; text-align:center;"><script language="javascript" type="text/javascript" src="http://synd.trulia.com/tools/chart/style_default300/type_average_listing_price/CA/Altadena/"></script></div>', 'second_image' => '<img src="altadena_home.jpg" height="195" width="200">', 'trulia' => '<style type="text/css"> .module {overflow:visible;}/*For typepad*/ #tMinistats { position:relative; width:180px; } #tMinistats .tMinistatsS { text-align:center; position:relative;bottom:0;margin-bottom:70px;width:95%; z-index:100;color:#b6d46f;font-family:Arial;font-size:11px; } #tMinistats .tMinistatsS a { color:#06c; }</style><div id="tMinistats" style="background-color:#ffffff;"> <script type="text/javascript" language="javascript" src="http://synd.trulia.com/tools/ministats/style_default180/CA/Altadena/"></script> </div>', 'second_image' => '<div style="position:relative; top:-30px; left:10px; border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena1.jpg" alt="Altadena Home" height="250" width="220"></div>', 'third_image' => '<div style="position:relative; top:-282px; left:260px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena2.jpg" alt="Altadena Home" height="250" width="220"></div>', 'fourth_image' => '<div style="position:relative; top:-535px; left:510px;margin-bottom: -500px;border: 2px solid black; height: 250px; width: 220px;"><img src="images/cities/altadena/altadena3.jpg" alt="Altadena Home" height="250" width="220"></div>' ), ); sort($cities); ?> I originally created this page as a single page layout that would have all the areas listed then would have them looking like a nice organized list. i called this page area_showings.php i created a foreach() loop that would call the array then the value foreach($cities as $city => $data){} this worked perfectly and was calling the data to the variable value and i could set the page up. I then decided that the idea of a long list of cities was not very user friendly and i decided to make is a dynamic page with a different structure. i wanted the user to go on area_showings.php and there he would select a link of his city interested in, and the page would then load the data based upon what the user had selected. <?php foreach ($cities as $city => $data){ echo <a href="area_showings.php?city=' . $data['name'] .'">'. $data['name'] . '</br></div>'; } ?> Now when a user selects the city he should be directed to the same page but now it would show the direct data based on the URL. This works fine and is passed correctly with the $_GET. MY ISSUE: I have created my conditional to check if the $_GET is empty or matches the correct city. but after the conditional i cant seem to understand how i can call the same $data[]; without a loop. i am use to MySQL where you can call for the $data using fetch_assoc to create the variables. if (empty($_GET['city']) === true){ ?> <div style="background-color:#A9B9C9;width:780px; height: auto; padding-left: 30px;padding-top: 30px; margin-left: 200px; margin-bottom: 20px; margin-top: 10px; border: black 5px solid;line-height: 25px;"> <?php foreach ($cities as $city => $data){ echo '<div style="height: 50px; width: auto; border: black solid 2px;font-size: 1.2em; padding: 10px 10px;"> <a href="area_showings.php?city=' . $data['name'] .'">'. $data['name'] . '</br></div>'; } ?> </div> <?php } else if (empty($_GET['city']) === false) { $name = $_GET['city']; if($name == 'Burbank' || $name == 'Glendale' || $name == 'Atwater Village' || $name == 'Pasadena' || $name == 'Altadena' || $name == 'Eagle Rock' || $name == 'Silverlake' || $name == 'Lancaster' || $name == 'Palmdale' || $name == 'Echo Park' || $name == 'Sorry! Didn\'t find your city? We can show more.'){ echo '<div style="background-color: #fff;padding: 10px 10px;height: auto; width:750px;border: 2px solid #000; border-radius: 15px;"> echo '<div style="background-color: #fff;padding: 10px 10px;height: auto; width:750px;border: 2px solid #000; border-radius: 15px;"> <div style="font-family:Lato, sans-serif, Helvetica, sans-serif;color:#2B4450; font-size: 30px; font=weight:bolder;margin-bottom:15px;margin-top:15px; text-transform: uppercase;">' . $data['name'] . '</div> <div style="height:250px; width:200px; border: black 4px solid; margin-bottom: -200px;"><a href="' . $data['link'] .'" target="_blank"><img src="images/cities/' . $data['picture'] . '" height="250" width="200"></a></div> <div style="position:relative;top:-55px;left:220px;height:250px; width: 0px;line-height:-50px;margin-top:-120px; padding-left: 10px; padding-top: 10px;border-radius: 10px;">' .$data['data'] . '<span style="position:relative; top: -200px; left: 320px;">' .$data['trulia'] . '</span></div><div style="width:auto; height; 300px; border-bottom: 3px solid black;">' . $data['second_image'] . $data['third_image'] . $data['fourth_image'] . '</div> <h2><span style="color:#2B4450; font-weight: bolder; font-family:Lato, sans-serif, Helvetica, sans-serif;">For more info</span> <a href="contact_us.php" class="info_Button">Click Here</a></h2> </div> </br>'; </div> </br>'; } } so just to clarify, i want to be able to use the correct array of data to the matching city of the $_GET with a multidimensional array without using a foreach loop. i want the info to be dynamic not listed. any suggestions ? implode function ? array_walk ?
  6. I apologize ahead of time if the code I post is too large. I did not see any posts regarding code length. I have the following array, that I created to be traversed and have specific parts passed into specific functions. $options = array( 'navigation' => array( 'page_title' => __('Aisis', 'aisis'), 'menu_title' => __('Aisis', 'aisis'), 'capabillity' => 'edit_themes', 'menu_slug' => 'aisis-core-options', 'function' => 'some_function', 'icon_url' => '', 'position' => '', 'sub_menues' => array( array( 'page_title' => __('Aisis', 'aisis'), 'menu_title' => __('Aisis', 'aisis'), 'capabillity' => 'edit_themes', 'menu_slug' => 'aisis-core-options', 'function' => 'some_function', ), array( 'page_title' => __('Aisis', 'aisis'), 'menu_title' => __('Aisis', 'aisis'), 'capabillity' => 'edit_themes', 'menu_slug' => 'aisis-core-options', 'function' => 'some_function', ), ) ), ); There are two main functions here that will be used add_menu_page() for the $options['navigation'] and add_submenu_page() for the $options['navigation']['submenues'] (yes I know there's a spelling mistake in submenues). The following code is a mess, how ever does almost what I need. Please bare with me, as It's no where near a finished product: foreach($options as $setting=>$option){ if($setting == 'navigation' && is_array($option)){ if(isset($option[$k])){ echo $option['page_title']; } foreach($option as $k=>$v){ if(is_array($v)){ foreach($v as $sub_menu){ foreach($sub_menu as $sk=>$sv){ if(isset($sub_menu[$sk])){ echo $sub_menu['menu_slug']; } } } } } } } Now what you'll see is something like echo $sub_menu['menu_slug'] - well, what if that key is not set? simple enough you say: if(isset($sub_menu['menu_slug'])){}else{} accept not, because this is where the functions come in handy, each key represents a value which is an argument for the function. no the function does not take an array of arguments, so, the question is: How do I take the array above and the code provided and do something like: foreach($option as $k=>$v){ if(is_array($v)){ foreach($v as $sub_menu){ foreach($sub_menu as $sk=>$sv){ if(isset($sub_menu[$sk])){ add_submenu_page($sub_menu['menu_slug'] /*...and so on....*/) } } } } } with out having to do a bunch of if is set, do this, else do that.I have to be able to pass in each individual key as a argument to the respected functions listed above, but I don't want to have to do a bunch of isset statements. I was thinking of doing something like in_array, or creating a walker that would look for the functions arguments. In case your wondering what the functions arguments are, look at the keys. they are the arguments, the values are the arguments values. So this is where I ask the community, what do I do? is there a simpler, cleaner way to achieve what I want?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.