EdgarsK Posted January 14, 2013 Report Share Posted January 14, 2013 Situācija <? $item = array('a'=>array('b'=>array('c'=>'none'))); $item = '$e[a][b][c]'; $$item = 'test'; echo $e[a][b][c]; // 'none'; Kods nav produkcijas kods, uzrkasitju to, jo būs vieglāk saprast nekā aizskaidrot. Kā lai panāku bez eval šo? vajag lai atgriež $$item kā 'test' Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted January 14, 2013 Author Report Share Posted January 14, 2013 tas ka mainīgie nesakrīt, ignorējat, nēesmu gulejis :D $item = array(...) $item2 = '$item[a]'; echo $$item2; Quote Link to comment Share on other sites More sharing options...
daGrevis Posted January 14, 2013 Report Share Posted January 14, 2013 http://codepad.org/oCfltGyE Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted January 14, 2013 Author Report Share Posted January 14, 2013 what? :D <?php $array = array( 'aa' => array( 'bb' => 20 ) ); $string = '$array[aa][bb]'; $$string = 30; echo $array[aa][bb]; // atgriez 20; Gribu saprast ka caur stringu varu iesetot Quote Link to comment Share on other sites More sharing options...
daGrevis Posted January 14, 2013 Report Share Posted January 14, 2013 Es nerunāju tavā valodā. Quote Link to comment Share on other sites More sharing options...
waplet Posted January 14, 2013 Report Share Posted January 14, 2013 http://php.net/manual/en/language.variables.php#58632 Quote Link to comment Share on other sites More sharing options...
briedis Posted January 14, 2013 Report Share Posted January 14, 2013 Tu kaut ko dari nepareizi... Ko tu gribi panākt? Quote Link to comment Share on other sites More sharing options...
ezis Posted January 14, 2013 Report Share Posted January 14, 2013 $f = create_function('$val','$array["aa"]["bb"] = $val; return $array;');var_dump($f(30)); Quote Link to comment Share on other sites More sharing options...
101111 Posted January 14, 2013 Report Share Posted January 14, 2013 Kas tas par sviestu? Varbūt serializācija ir tas ko tu meklē? Quote Link to comment Share on other sites More sharing options...
php newbie Posted January 15, 2013 Report Share Posted January 15, 2013 $item = array('a'=>array('b'=>'test')); $str = '$item[a][b]'; $item2 = ${substr($str, 1, 4)}[substr($str, 6, 1)][substr($str, 9, 1)]; echo $item2; bet labāk tā nedarīt :) Quote Link to comment Share on other sites More sharing options...
aaxc Posted January 15, 2013 Report Share Posted January 15, 2013 Ja es tevi pareizi saprotu, tad tu vēlies izmantot eval funkciju. <?php $array = array( 'aa' => array( 'bb' => 20 ) ); $string = '$array[\'aa\'][\'bb\']'; eval( $string . ' = 30;' ); echo $array['aa']['bb']; ?> Quote Link to comment Share on other sites More sharing options...
daGrevis Posted January 15, 2013 Report Share Posted January 15, 2013 Kāpēc kaut kas tāds ir jādara? Quote Link to comment Share on other sites More sharing options...
aaxc Posted January 15, 2013 Report Share Posted January 15, 2013 Lai čerez ž nomainītu masīva vērtību neiedziļinoties, kur un kāpēc tas tiek veidots. Quote Link to comment Share on other sites More sharing options...
v3rb0 Posted January 15, 2013 Report Share Posted January 15, 2013 un tā rodas stāsti, ka php sux. Quote Link to comment Share on other sites More sharing options...
F3llony Posted January 15, 2013 Report Share Posted January 15, 2013 un tā rodas stāsti, ka php sux. Patiesi, patiesi... 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.