Alnis Posted November 9, 2009 Report Share Posted November 9, 2009 Jautājums par aarajiem Tatda ir: $a1=array(‘a’=>”AAA1”, ‘b’=>”BBB1”, ‘c’=>”CCC1”); $a2=array(‘a’=>”AAA2”, ‘b’=>”BBB2”, ‘c’=>”CCC2”); $a3=array(‘a’=>”AAA3”, ‘b’=>”BBB3”, ‘c’=>”CCC3”); to visu man vajag salikt taa, lai butu massivs: $masivs: [1] => Array { [a] => AAA1 [b] => BBB1 [c] => CCC1 } [2] => Array { [a] => AAA2 [b] => BBB2 [c] => CCC2 } [3] => Array { [a] => AAA3 [b] => BBB3 [c] => CCC3 } ar sadu risinajumu: $masivs[1]=array_values($a1); $masivs[2]=array_values($a1); $masivs[3]=array_values($a1); iegustam so: [1] => Array { [1] => AAA1 [2] => BBB1 [3] => CCC1 } [2] => Array { [1] => AAA2 [2] => BBB2 [3] => CCC2 } [3] => Array { [1] => AAA3 [2] => BBB3 [3] => CCC3 } bet vajag iegut pirmo variantu...kaa to dabut? skaidrs, ka array_values visus indexus saliek pa jaunam un tie ir integeri, bet man vajag saglabat stringus esosos! Paldies par jebkadam idejam :) Quote Link to comment Share on other sites More sharing options...
tas_pats Posted November 10, 2009 Report Share Posted November 10, 2009 (edited) $masivs = array('a' => $a1,'b' => $a1,'c' => $a3); Edited November 10, 2009 by tas_pats Quote Link to comment Share on other sites More sharing options...
PheliX Posted November 10, 2009 Report Share Posted November 10, 2009 $masivs[1]=$a1; $masivs[2]=$a2; $masivs[3]=$a3; Quote Link to comment Share on other sites More sharing options...
2easy Posted November 10, 2009 Report Share Posted November 10, 2009 $masivs = array($a1, $a2, $a3); Quote Link to comment Share on other sites More sharing options...
Alnis Posted November 10, 2009 Author Report Share Posted November 10, 2009 (edited) $masivs = array($a1, $a2, $a3); ok, sitais der.... bet kaa man darit, lai apvienotu arrays teksim man $masivs = array($a1); kuram pec tam vajag pielikt klat $masivs = array($a2) bet ne lai neuzrakstas pa virsu! proti, kaa apvoenoy $masivs = array($a1, $a2) ar array($a3) .... ar array(aN)) Edited November 10, 2009 by Alnis Quote Link to comment Share on other sites More sharing options...
Alnis Posted November 10, 2009 Author Report Share Posted November 10, 2009 taa, atrisinaju sito probzu ar $masivs = array_merge((array)$masivs,array($a)); Quote Link to comment Share on other sites More sharing options...
2easy Posted November 11, 2009 Report Share Posted November 11, 2009 papildināt masīvu var arī vienkāršāk ;) $masivs[] = $a1; $masivs[] = $a2; ... $masivs[] = $aN; lasīt manuāli mūsdienās laikam vairs neskaitās stilīgi... :P http://www.php.net/manual/en/language.types.array.php Quote Link to comment Share on other sites More sharing options...
Alnis Posted November 12, 2009 Author Report Share Posted November 12, 2009 kaa ar sort() funkciju var sasortet sitadu masiu [1] => Array { [a] => AAA1 [b] => BBB1 [c] => 2 } [2] => Array { [a] => AAA2 [b] => BBB2 [c] => 3 } [3] => Array { [a] => AAA3 [b] => BBB3 [c] => 1 } lai vins izskatas: [1] => Array { [a] => AAA3 [b] => BBB3 [c] => 1 } [2] => Array { [a] => AAA1 [b] => BBB1 [c] => 2 } [3] => Array { [a] => AAA2 [b] => BBB2 [c] => 3 } Proti es velos, lai sortesana notiek pec otra indexa arrajaa $masivs[][c] - pec "c" :) Quote Link to comment Share on other sites More sharing options...
2easy Posted November 12, 2009 Report Share Posted November 12, 2009 lai kko tādu varētu izdarīt ar sort() funkciju, laikam nāktos mainīt php source un pēc tam to pārkompilēt. vienkāršāk būtu, ja tu uztaisītu savu sortēšanas funkciju speciāli šim gadījumam (array salīdzināšana pēc konkrēta key), izmantojot kādu no tiem sortēšanas algoritmiem, kurus esi mācījies skolā/augstskolā. starp citu vai tu gadījumā necenties uztaisīt pats savu db ar šiem arrayiem? :D Quote Link to comment Share on other sites More sharing options...
2easy Posted November 12, 2009 Report Share Posted November 12, 2009 haha tomēr nevajadzēs pašam taisīt sortēšanu. php tiešām par visu ir padomāts :P array_multisort() ftw $a[] = array('a' => 'AAA1', 'b' => 'BBB1', 'c' => 2); $a[] = array('a' => 'AAA2', 'b' => 'BBB2', 'c' => 3); $a[] = array('a' => 'AAA3', 'b' => 'BBB3', 'c' => 1); for ($i = 0; $i < count($a); $i++) $aSort[] = $a[$i]['c']; array_multisort($aSort, SORT_ASC, $a); echo '<textarea rows="25" cols="80">'; print_r($a); echo '</textarea>'; /* Array ( [0] => Array ( [a] => AAA3 [b] => BBB3 [c] => 1 ) [1] => Array ( [a] => AAA1 [b] => BBB1 [c] => 2 ) [2] => Array ( [a] => AAA2 [b] => BBB2 [c] => 3 ) ) */ c'mon tauta lasām taču manuāli!!! Quote Link to comment Share on other sites More sharing options...
Alnis Posted November 12, 2009 Author Report Share Posted November 12, 2009 (edited) mana izglitiba nav saistita ar datoriem, es sava valasprieka del meginu/ macos kaut ko uzkodet :) skaidrs, ka netaisos php source mainit :)) Griibu panakt vienu lietinu bez db palidzibas :), lidz sim ar masiviem bija maz saskarsme, nekad nebiju lietojis masivus, kuros ir apakmasivi un nekad neesmu nemies ar datu dazadu sortesanu, kartosanu saskaitisanu pasa masivaa ieksaa :) Pamazam apgustu massivus :) Paaldies :) 2easy, ju ar da best :) Edited November 12, 2009 by Alnis Quote Link to comment Share on other sites More sharing options...
2easy Posted November 12, 2009 Report Share Posted November 12, 2009 ^^ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.